题意:n个凳子m个人,每个人至少隔k,问有多少种方案数mod 1e9+7
思路:考虑先固定一个人,那么就有剩下m-1个人和n-1张凳子,因为每人之间至少隔k个,那么抽出m*k张凳子,剩下n-1-m*k张凳子分配给m-1个人,那么就是C(n-1-m*k,m-1),因为有n个人,所以乘个n,因为这里的人是没有区别的,所以需要除以m来去掉同样的方案数
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int mod = 1e9+7;
LL qpow(LL x,int n)
{
LL ans = 1;
for(;n;n>>=1)
{
if(n&1)ans=ans*x%mod;
x=x*x%mod;
}
return ans;
}
LL C(int n,int m)
{
if(m>n)return 0;
LL ans = 1;
for(int i = 1;i<=m;i++)
ans = ans*((n+i-m)*qpow(i,mod-2)%mod)%mod;
return ans;
}
LL n,m,k;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld%lld",&n,&m,&k);
if(m==1)printf("%lld\n",n);
else printf("%lld\n",(C(n-k*m-1,m-1)*n%mod)*qpow(m,mod-2)%mod);
}
}
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