4045 Machine scheduling(The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest)

Machine scheduling

Problem Description
A Baidu’s engineer needs to analyze and process large amount of data on machines every day. The machines are labeled from 1 to n. On each day, the engineer chooses r machines to process data. He allocates the r machines to no more than m groups ,and if the difference of 2 machines’ labels are less than k,they can not work in the same day. Otherwise the two machines will not work properly. That is to say, the machines labeled with 1 and k+1 can work in the same day while those labeled with 1 and k should not work in the same day. Due to some unknown reasons, the engineer should not choose the allocation scheme the same as that on some previous day. otherwise all the machines need to be initialized again. As you know, the initialization will take a long time and a lot of efforts. Can you tell the engineer the maximum days that he can use these machines continuously without re-initialization.

Input
Input end with EOF.
Input will be four integers n,r,k,m.We assume that they are all between 1 and 1000.

Output
Output the maxmium days modulo 1000000007.

Sample Input
5 2 3 2

Sample Output
6

Hint

Sample input means you can choose 1 and 4,1 and 5,2 and 5 in the same day.
And you can make the machines in the same group or in the different group.
So you got 6 schemes.
1 and 4 in same group,1 and 4 in different groups.
1 and 5 in same group,1 and 5 in different groups.
2 and 5 in same group,2 and 5 in different groups.
We assume 1 in a group and 4 in b group is the same as 1 in b group and 4 in a group.

题意是说给你1到n个连续的数,让你从中选择其中差值都大于k的r个数,然后把这r个数分成不超过m组,有多少种分法
首先看选择其中差值大于k的r个数:我们可以用隔板法来想,就是有r个数,然后把剩余的球插入其中k-1个空格中,一共有n-(k-1)(r-1)个空格,要选r个,就是C[n-(k-1) (r-1)][r]中选择,然后是将r个机器分成不多于m中情况,这时候用第二类strling数,两式相乘

#include<bits/stdc++.h>
using namespace std;
using LL =int64_t;
const int maxn=1005;
const int mod=1e9+7;
LL ans[2*maxn][2*maxn],str[maxn][maxn];

void init() {
    for(int i=1;i<=2000;i++) {
            ans[i][0]=ans[i][i]=1;
        for(int j=1;j<i;j++) {
            ans[i][j]=(ans[i-1][j]+ans[i-1][j-1])%mod;
        }
    }
    for(int i=1;i<=1000;i++) {
        str[i][0]=0,str[i][i]=1;
        for(int j=1;j<i;j++)
        str[i][j]=((LL)j*str[i-1][j]+str[i-1][j-1])%mod;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    init();
    LL n,r,k,m;
    while(cin>>n>>r>>k>>m) {
        LL p=n-(r-1)*(k-1);
        if(p<0) cout<<0<<endl;
        else  {
            LL sum=0;
            for(int i=1;i<=min(r,m);i++) {
                sum=(sum+str[r][i])%mod;
            }
            cout<<(sum*ans[p][r])%mod<<endl;
        }
    }
    return 0;
}

其中strling的递推式是:str[i][j]=((LL)j*str[i-1][j]+str[i-1][j-1])表示将i个数分成j组有多少种情况

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值