hannnnah_j’s Biological Test HDU - 5894 (组合数)

 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

这题是一个组合数学的题,因为每个椅子是不一样的,所以其实看成链状的而不是环,我们假定链的第一个位置已经坐了人,并且顺带带走了k*m个点,而且我们把1+k个点浓缩成一个点,那么m-1个这样的点来放剩下的n-1-k*m个格子即可,然后我们可以截成n种不同的链所以要乘n,但是有因为是循环放置的,而且每个人是相同的所以通构的会有m种,因为是旋转的,所以要除m。
m等于1的时候要特判

#include<iostream>
#include<cstdio>
#include<cstring>
#define mod 1000000007
#define N 1000005
using namespace std;
long long fac[N];
long long inv[N];
long long P(long long a,long long b)
{
    long long ans=1;
    while(b)
    {
        if(b&1)
            ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
long long get(int n,int m)
{
    return (fac[n]*inv[m]%mod)*inv[n-m]%mod;
}
void init()
{
    fac[0]=1;
    inv[0]=1;
    for(int i=1;i<N;i++)
        fac[i]=fac[i-1]*i%mod;
    inv[N-1]=P(fac[N-1],mod-2);
    for(int i=N-2;i>=1;i--)
        inv[i]=inv[i+1]*(i+1)%mod;
}

int main()
{   
    init();
    int n,m,k;
    int t;
    //cout<<get(10,5)<<endl;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&n,&m,&k);
        if(m==1)
            printf("%d\n",n);
        else
            if(n<(k+1)*m)
                printf("0\n");
            else
            {
                long long ans=get(n-1-k*m,m-1);
                ans=ans*n%mod;
                ans=ans*P(m,mod-2)%mod;
                printf("%lld\n",ans);
            }   
    }   
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值