HDU Machine scheduling

时间:2023-03-09 15:32:57
HDU Machine scheduling

Machine scheduling

Time Limit : 5000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 4   Accepted Submission(s) : 1

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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.

Source

The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest  

有N个机器,每天选出R个机器,而且每两个机器的编号差要大于等于K,而且每天将R
个机器最多分为M组工作,问最多有多少种方案。

 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef __int64 LL; LL p = ;
LL dp[][];
LL f[][]; void init()
{
for(int i=;i<=;i++){
for(int j=;j<=i;j++){
if(j==)dp[i][j]=;
else if(j==i)dp[i][j]=;
else dp[i][j] = (j*dp[i-][j]+dp[i-][j-])%p;
}
}
for(int i=;i<=;i++)
for(int j=;j<=i;j++)
dp[i][j] = (dp[i][j]+dp[i][j-])%p;
}
int main()
{
int n,r,k,m;
init();
while(scanf("%d%d%d%d",&n,&r,&k,&m)>)
{ /** f[i][j] i个数字 最大为j 有多少种方法 **/ for(int i=;i<=;i++)for(int j=;j<=;j++) f[i][j]=;
int kk = n-k;
for(int i=;i<=n;i++)f[][i]=; for(int i=;i<=r;i++)
{
LL hxl = ;
for(int j=;j<=kk;j++){
hxl = (hxl+f[i][j])%p;
f[i+][j+k]=hxl;
}
}
LL sum = ;
for(int i=;i<=n;i++) sum =(sum+f[r][i])%p;
printf("%I64d\n",(sum*dp[r][min(r,m)])%p);
}
return ;
}