Machine scheduling HDU - 4045 第二类striling 数

题意有点难懂,其实就是让你从1-n中选r个数的间隔不小于k,然后她们的放在m个不区分的盒子里的数量。
第一步,有多少数可以选,我们先选(r-1)个间隔为k的,之后的可以任意选了,
所以为n-(r-1)*k+r-1,然后在这些数中选r个。

第二步,是第二类striling数,将p元素划分到k个不可区分的盒子,让k从1到m,求和即可

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

#define LL long long
#define inf 1000000007
const int maxn = 1005;

LL s[maxn][maxn];


LL ni(LL b,LL n)
{
    LL x=1;
    while(n)
    {
        if(n&1) x=(x*b)%inf;
        b=(b*b)%inf;
        n>>=1;
    }
    return x%inf;
}
LL Cm(LL n,LL m)
{
    if(m>n) return 0;
    else if(m==n) return 1;
    if(m>n/2) m=n-m;
    LL a=1,b=1;
    for(int i=0;i<m;i++)
    {
        a=(a*(n-i))%inf;
        b=(b*(i+1))%inf;
    }
    return (a*ni(b,inf-2))%inf;
}

int main()
{
    s[0][0]=1;s[1][1]=1;
    for(int i=1;i<=maxn;i++)
        for(int j=1;j<=i;j++)
             s[i][j]=(j*s[i-1][j]+s[i-1][j-1])%inf;
    int n,r,k,m;
    while(scanf("%d %d %d %d",&n,&r,&k,&m)!=EOF)
    {
        LL b=n-k*(r-1)+r-1;
        LL a=0;
        if(b<0) b=0;
        b=Cm(b,r);
        for(int i=1;i<=m;i++)
        {
            a=(a+s[r][i])%inf;
        }
        printf("%I64d\n",(a*b)%inf);
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值