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.
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
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个座位要安排m个人,每两个人之间至少隔k个位置,问方案数。 分析:m个人有m个空隙,设第i个空隙为ai,则有a1+a2+a3...+am = n-m,其中ai >= k,问题可以转化为 b1+b2..+bn = n-m-m*k的非负解的个数,答案是C(n-m*k-1,m-1),因为有n个位置所以答案乘n,然后对于方程的一个解可以转m次得到m种解,所以答案还要除以m。#include<iostream> #include<string> #include<algorithm> #include<cstdlib> #include<cstdio> #include<set> #include<map> #include<vector> #include<cstring> #include<stack> #include<cmath> #include<queue> #define INF 0x3f3f3f3f #define MOD 1000000007 #define N 1000005 using namespace std; int T; long long n,m,k,F[N]; void init(long long p) { F[0] = 1; for(int i = 1;i < N;i++) F[i] = F[i-1]*i % p; } long long inv(long long a,long long m) { if(a == 1)return 1; return inv(m%a,m)*(m-m/a)%m; } long long Lucas(long long n,long long m,long long p) { long long ans = 1; while(n&&m) { long long a = n%p; long long b = m%p; if(a < b)return 0; ans = ans*F[a]%p*inv(F[b]*F[a-b]%p,p)%p; n /= p; m /= p; } return ans; } int main() { init(MOD); scanf("%d",&T); while(T--) { scanf("%lld%lld%lld",&n,&m,&k); printf("%d\n",(Lucas(n-1-m*k,m-1,MOD)*n % MOD) * inv(m,MOD) % MOD); } }