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组工作,问最多有多少种方案。

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<cstring>
 4 #include<cstdlib>
 5 using namespace std;
 6 typedef __int64 LL;
 7
 8 LL p = 1000000007;
 9 LL dp[1002][1002];
10 LL f[1002][1002];
11
12 void init()
13 {
14     for(int i=1;i<=1000;i++){
15         for(int j=1;j<=i;j++){
16             if(j==1)dp[i][j]=1;
17             else if(j==i)dp[i][j]=1;
18             else dp[i][j] = (j*dp[i-1][j]+dp[i-1][j-1])%p;
19         }
20     }
21     for(int i=1;i<=1000;i++)
22     for(int j=2;j<=i;j++)
23     dp[i][j] = (dp[i][j]+dp[i][j-1])%p;
24 }
25 int main()
26 {
27     int n,r,k,m;
28     init();
29     while(scanf("%d%d%d%d",&n,&r,&k,&m)>0)
30     {
31
32         /** f[i][j] i个数字 最大为j 有多少种方法 **/
33
34         for(int i=1;i<=1000;i++)for(int j=1;j<=1000;j++) f[i][j]=0;
35         int kk = n-k;
36         for(int i=1;i<=n;i++)f[1][i]=1;
37
38         for(int i=1;i<=r;i++)
39         {
40             LL hxl = 0;
41             for(int j=1;j<=kk;j++){
42                 hxl = (hxl+f[i][j])%p;
43                 f[i+1][j+k]=hxl;
44             }
45         }
46         LL sum = 0;
47         for(int i=1;i<=n;i++) sum =(sum+f[r][i])%p;
48         printf("%I64d\n",(sum*dp[r][min(r,m)])%p);
49     }
50     return 0;
51 }
时间: 2024-10-28 22:07:58

HDU Machine scheduling的相关文章

HDU 4045 Machine scheduling (组合数学-斯特林数,组合数学-排列组合)

Machine scheduling Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1000    Accepted Submission(s): 363 Problem Description A Baidu's engineer needs to analyze and process large amount of data o

hdu 4045 Machine scheduling [ dp + 斯特林数]

传送门 Machine scheduling Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1048    Accepted Submission(s): 387 Problem Description A Baidu’s engineer needs to analyze and process large amount of dat

HDU 4045 Machine scheduling --第二类Strling数

题意: n个数(1~n)取出r个数,取出的数相差要>=k, 然后分成m个可空组,问有多少种情况. 解法: 先看从n个数中取r个相差>=k的数的方法数,可以发现 dp[i][j] = dp[1][j-1] + dp[2][j-1] + ... + dp[i-k][j-1],(dp[i][1] = i)  即维护一个前缀和即可,可以在O(r*n)内得出. 然后n个不同的数分成m个可以空的组,即为第二类Strling数的和 : S[n][1] + S[n][2] + ... + S[n][m]. S

HDU 4045 Machine scheduling (第二类斯特林数+DP)

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

HDU 1150:Machine Schedule(二分匹配,匈牙利算法)

Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5371    Accepted Submission(s): 2658 Problem Description As we all know, machine scheduling is a very classical problem in compu

HDU——T 1150 Machine Schedule

http://acm.hdu.edu.cn/showproblem.php?pid=1150 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9463    Accepted Submission(s): 4757 Problem Description As we all know, machine scheduling is a ve

hdu 1150 Machine Schedule(二分图-最小顶点覆盖)

Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5424    Accepted Submission(s): 2691 Problem Description As we all know, machine scheduling is a very classical problem in compu

hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1150 Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history.

hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6733    Accepted Submission(s): 3375 Problem Description As we all know, mach