OJ-Problems-Source/QUSTOJ/1840_x7536110.cpp

57 lines
1.5 KiB
C++
Raw Normal View History

2016-10-12 11:31:08 +08:00
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int P = 1e9+7;
const int maxn = 1e6+10;
ll f[maxn], r[maxn];
ll C(int n,int m){ return n < m? 0 : f[n]*r[n-m]%P*r[m]%P;}
ll lucas(int n,int m){
if(n < m) return 0;
if(!m||n == m) return 1;
return C(n%P, m%P)*lucas(n/P, m/P)%P;
}
void init(){
int i;
for(r[0] = r[1] = f[0] = f[1] = 1, i = 2; i < maxn; i++){
f[i] = f[i-1]*i%P, r[i] = -r[P%i]*(P/i)%P;
while(r[i] < 0) r[i] += P;
}
for(i = 2; i < maxn; i++)
r[i] = r[i]*r[i-1]%P;
}
ll solve(int n, int m, int k){//n个位置链选m个间隔 >= k
return C(n-(m-1)*k, m);
}
int main(){
//freopen("in", "r", stdin);
//freopen("out", "w", stdout);
init();
int T; scanf("%d", &T);
ll n, m, k;
while(T--){
scanf("%lld%lld%lld", &n, &m, &k);
if(m == 1) printf("%lld\n", n);
else if((k+1)*m > n) puts("0");
else {
ll ans = ( solve(n-2*k-1, m-1, k)*k%P + solve(n-k, m, k))%P;
printf("%lld\n", ans);
}
}
}
/*
1n个不同的座位m个座位给学生安排座位k个空座位
1e9+7
0 < m < n < 1e6, 0 < k < 1000, T <= 1000
input
2
4 2 6
5 2 1
output
0
5
2
1,2,3,4,5
21(1,3)(1,4)(2,4)(2,5)(3,5)5
*/