得到公式为:n * C(n - 1- m * k,m - 1) * n / m,记得特判一下m == 1即一个人的情况。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
using namespace std;
const int maxn = 20 + 5;
#define INF 0x3f3f3f3f
#define clr(x,y) memset(x,y,sizeof x )
typedef long long ll;
#define eps 10e-8
const int Mod = 1e9 + 7;
typedef pair<int, int> P;
ll pows(ll x,ll n)
{
ll ret = 1;
while(n)
{
if(n & 1)ret = ret * x % Mod;
n >>= 1;x = x * x % Mod;
}
return ret;
}
ll n,m,k;
void solve()
{
if(n - 1 - m * k < m - 1)
{
puts("0");return;
}
ll ans = 1;
for(int i = 1; i <= m - 1; i ++)
{
ans = ans * (n - 1 - m * k - i + 1) % Mod * pows(i,Mod - 2) % Mod;
}
ans = ans * n % Mod * pows(m,Mod - 2) % Mod;
printf("%I64d\n",(ans + Mod ) % Mod );
}
int main()
{
// freopen("out.txt","r",stdin);
int Tcase;scanf("%d",&Tcase);
while( Tcase --)
{
scanf("%I64d%I64d%I64d",&n,&m,&k);
if(m == 1)
{
printf("%I64d\n",n);continue;
}
solve();
}
return 0;
}