2016 ACM/ICPC Asia Regional Shenyang Online HDU 5894 hannnnah_j’s Biological Test

hannnnah_j’s Biological Test

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 508    Accepted Submission(s): 164


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
 【题意】给出n个不同的围成一圈的座位,现在有m个人,要求每两个人之间要空至少k个座位,问有多少种方案。
【解题方法】m个人要坐m个座位,还要至少空m*k个座位,剩下的就是n-m*(k+1)个座位了,放在m个间隔中,就是相同的球放在不同的盒子那个模型了。C(n-m*k-1,m-1),然后n个不同的座位那么就可以有n种不同的开始方式,然后这其中的每一种方式都被算了m次。所以C(n-m*k-1,m-1)*n/m就是答案了。直接套Lucas就行啦。
【AC 代码】
//
//Created by just_sort 2016/9/12 22:16
//Copyright (c) 2016 just_sort.All Rights Reserved
//

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 1000005;
const LL mod = 1e9+7;
LL fac[maxn];
void init()
{
    fac[0]=1LL;
    for(int i=1; i<maxn; i++){
        fac[i] = i*fac[i-1]%mod;
    }
}
LL powmod(LL a,LL n)
{
    LL res=1,temp=a%mod;
    while(n){
        if(n&1) res = res*temp%mod;
        temp = (temp%mod)*(temp%mod)%mod;
        n>>=1;
    }
    return res;
}
LL C(int n,int m){
    if(m>n) return 0;
    return fac[n]*powmod(fac[m]*fac[n-m]%mod,mod-2)%mod;
}
LL Lucas(int n,int m)
{
    if(m==0) return 1;
    return C(n%mod,m%mod)*Lucas(n/mod,m/mod)%mod;
}

int main()
{
    int T,n,m,k;
    init();
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&n,&m,&k);
        printf("%I64d\n",((Lucas(n-m*k-1,m-1)%mod*n)%mod)*powmod(1LL*m,mod-2)%mod);
    }
    return 0;
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值