New Year and Permutation

C. New Year and Permutation

参考:Codeforces Round Hello 2020 A~E 题解

发现了一个网站OEIS,如果打表找规律的话会很方便,虽然这道题没有用上....

具体思路可看参考视频。

一般数学题都是打表找规律,如果找不出规律,例如像这种排列组合的问题,就可以考虑分情况讨论,最后进行累加即可。

代码:

// Created by CAD on 2020/1/6.
#include <bits/stdc++.h>
#define mst(name, value) memset(name,value,sizeof(name))
#define ll long long
using namespace std;

const int maxn=250005;
ll c[maxn];
int mod;
ll jc(ll x)
{
    if(~c[x]) return c[x];
    else return c[x]=x*jc(x-1)%mod;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;   cin>>n>>mod;
    mst(c,-1);
    c[0]=c[1]=1;
    ll ans=0;
    for(int i=1;i<=n;++i)
        ans=(ans+(n-i+1)*jc(i)%mod*jc(n-i+1)%mod+mod)%mod;
    cout<<ans<<endl;
    return 0;
}
全部评论

相关推荐

10-27 02:29
已编辑
门头沟学院 嵌入式工程师
牛客72783561...:简历不是这么写的,你这两个项目只说了用到了什么技术,却没说取得了什么成果,在我看来这就是你自己做的一个demo,没有价值。你为什么不写你电赛国二的那个项目?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务