HDU 5894 hannnnah_j’s Biological Test ——(组合数)

  思路来自于:http://blog.csdn.net/lzedo/article/details/52585170

  不过并不需要卢卡斯定理,直接组合数就可以了。

  代码如下:

 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <string.h>
 4 using namespace std;
 5 typedef long long ll;
 6 const int mod = (int)1e9 + 7;
 7 const int N = 1000000 + 5;
 8 
 9 int m,n,k;
10 int fac[N];
11 int qpow(int a,int b)
12 {
13     int ans = 1;
14     while(b)
15     {
16         if(b&1) ans = 1LL* ans * a % mod;
17         b >>= 1;
18         a = 1LL* a * a % mod;
19     }
20     return ans;
21 }
22 
23 int C(int n,int m)
24 {
25     if(n<m) return 0;
26     return 1LL* fac[n] * qpow(1LL*fac[m]*fac[n-m]%mod,mod-2) % mod;
27 }
28 
29 void init()
30 {
31     fac[1] = 1;
32     for(int i=2;i<N;i++)
33     {
34         fac[i] = 1LL* fac[i-1] * i % mod;
35     }
36 }
37 
38 int main()
39 {
40     init();
41     int T;scanf("%d",&T);
42     while(T--)
43     {
44         scanf("%d%d%d",&n,&m,&k);
45         if(m==1) printf("%d
",n);
46         else
47         {
48             printf("%d
",(int)(1LL*C(n-m*k-1,m-1)*n%mod*qpow(m,mod-2)%mod));
49         }
50     }
51 }
原文地址:https://www.cnblogs.com/zzyDS/p/5889759.html