hdu5894hannnnah_j’s Biological Test

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5894

题意:有n个座位(环),求m个人坐上去且两个人相隔至少k个空座位的方案数。

分析:先确定1个人的位置,那么剩下的就是C(n-m*k-1,m-1),那么有n*C(n-m*k-1,m-1)种方案然后/m去掉重复的。

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=1000010;
const int M=50010;
const int mod=1000000007;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int INF=1000000010;
const ll MAX=1ll<<55;
const double eps=1e-5;
const double inf=~0u>>1;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
ll inv[N];
ll C(ll n,ll m) {
    if (m>n) return 0;
    ll ret=1;
    m=min(m,n-m);
    for (int i=1;i<=m;i++) (ret*=(n-i+1)*inv[i]%MOD)%=MOD;
    return ret;
}
int main()
{
    int t;
    ll n,m,k;
    inv[1]=1ll;
    for (int i=2;i<N;i++)
    inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
    scanf("%d", &t);
    while (t--) {
        scanf("%lld%lld%lld", &n, &m, &k);
        if (m==1) printf("%lld\n", n);
        else printf("%lld\n", (C(n-m*k-1,m-1)*n%MOD)*inv[m]%MOD);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值