AcWing 230. 排列计数 水题(组合数+错排)打卡
2021-05-20 14:31
阅读:640
标签:++ href tps else col name win 水题 its
题目:https://www.acwing.com/problem/content/232/
#include#define ll long long #define mod 1000000007 using namespace std; const int maxn = 1000005; ll dp[maxn],inv[maxn],fac[maxn],inv_fac[maxn]; void init() { inv[0]=inv[1]=inv_fac[0]=fac[0]=1; dp[1]=0;dp[2]=1; for(int i=2; i mod; for(int i=1; i 1]*i%mod; for(int i=1; i 1]*inv[i]%mod; for(int i=3; i 1)*(dp[i-2]+dp[i-1])%mod; } ll C(int n,int m) { return fac[n]*inv_fac[m]%mod*inv_fac[n-m]%mod; } int main() { init(); ll n,m,t; scanf("%lld",&t); while(t--){ scanf("%lld%lld",&n,&m); if(n==m) printf("1\n"); else printf("%lld\n",(C(n,m)*dp[n-m])%mod); } }
AcWing 230. 排列计数 水题(组合数+错排)打卡
标签:++ href tps else col name win 水题 its
原文地址:https://www.cnblogs.com/Lis-/p/11295988.html
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:AcWing 230. 排列计数 水题(组合数+错排)打卡
文章链接:http://soscw.com/index.php/essay/87919.html
文章标题:AcWing 230. 排列计数 水题(组合数+错排)打卡
文章链接:http://soscw.com/index.php/essay/87919.html
评论
亲,登录后才可以留言!