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
Input
Input will be four integers n,r,k,m.We assume that they are all between 1 and 1000.
Output
Sample Input
5 2 3 2
Sample Output
6
Hint
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
有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 }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。