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



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
  
  
2 4 2 6 5 2 1
 

Sample Output
  
  
0 5
 

题目大意:老师为防止学生作弊,因此让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  1000000007
long 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);
	  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值