ICPC-第三场网络赛-3-hannnnah_j’s Biological Test(组合数应用)

来源:互联网 发布:xmanager连接linux图形 编辑:程序博客网 时间:2024/04/28 12:02


hannnnah_j’s Biological Test

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 180    Accepted Submission(s): 49


Problem Description
hannnnah_j is a teacher in WL High school who teaches biology.

One day, she wants to test m students, thus she arranges n different seats around a round table.

In order to prevent cheating, she thinks that there should be at least k empty seats between every two students.

hannnnah_j is poor at math, and she wants to know the sum of the solutions.So she turns to you for help.Can you help her? The answer maybe large, and you need to mod 1e9+7.
 

Input
First line is an integer T(T≤1000).
The next T lines were given n, m, k, respectively.
0 < m < n < 1e6, 0 < k < 1000
 

Output
For each test case the output is only one integer number ans in a line.
 

Sample Input
24 2 65 2 1
 

Sample Output
05
 

题目大意:老师为防止学生作弊,因此让n个学生坐在一张大圆桌考试,这个圆桌有n个座位,总共有m个学生
,但是规定任意两个学生之间必须各k个座位,问你有多少种坐法(ps:学生之间看做相同,但是座位不同)。
题解:组合数公式的拓展(详见代码)
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<limits.h>#include<algorithm>#include<queue>#include<stack>#include<vector>#include<math.h>#include<map>using namespace std;#define maxn 1000001#define Mod  1000000007long long n,m,k,a[maxn],b[maxn];long long zuhe(long long x,long long y){return a[x]*b[x-y]%Mod*b[y]%Mod;}long long Pow(long long x,long long y){long long ans=1;while(y){if(y&1)  ans=ans*x%Mod;x=x*x%Mod;y/=2;}return ans;}int  main(){int T,i,j;scanf("%d",&T);a[0]=b[0]=1;for(i=1;i<maxn;i++){  a[i]=a[i-1]*i%Mod;  b[i]=Pow(a[i],Mod-2)%Mod;    }  while(T--)  {    scanf("%lld%lld%lld",&n,&m,&k);    long long ans;    if(m==1) ans=n;    else if(m*(k+1)>n)ans=0;    else    {     ans=zuhe(n-m*k,m)%Mod;     ans=(ans+zuhe(n-m*k-1,m-1)*k)%Mod;      }      printf("%lld\n",ans);  }}

0 0