HDU 1158 Employment Planning
来源:互联网 发布:如何做数据统计 编辑:程序博客网 时间:2024/05/17 22:39
Employment Planning
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2754 Accepted Submission(s): 1084
Problem Description A project manager wants to determine the number of the workers needed in every month. He does know the minimal number of the workers needed in each month. When he hires or fires a worker, there will be some extra cost. Once a worker is hired, he will get the salary even if he is not working. The manager knows the costs of hiring a worker, firing a worker, and the salary of a worker. Then the manager will confront such a problem: how many workers he will hire or fire each month in order to keep the lowest total cost of the project.
Input The input may contain several data sets. Each data set contains three lines. First line contains the months of the project planed to use which is no more than 12. The second line contains the cost of hiring a worker, the amount of the salary, the cost of firing a worker. The third line contains several numbers, which represent the minimal number of the workers needed each month. The input is terminated by line containing a single '0'.
Output The output contains one line. The minimal total cost of the project.
Sample Input
3
4 5 6
10 9 11
0
Sample Output
199
1 /* 2 dp[i][j]表示第i个月雇佣了j个人花费的最少费用 3 if(j>=k) dp[i][j] = min(dp[i][j],dp[i-1][k]+hire*(j-k)+j*sal); 4 else dp[i][j] = min(dp[i][j],dp[i-1][k]+fire*(k-j)+j*sal); 5 其实就是遍历一遍第i个月可以雇佣的人数,再遍历一遍第i-1个月可以雇佣的人数, 6 若i-1个月时人多,则炒掉,否则则雇佣,因为第i组仅参考第i-1组的话,没必要 7 留下不干活的人。这样遍历下去,所有情况就都考虑到了。 8 9 15MS 280K10 */11 #include <iostream>12 #include <cstdio>13 #include <cstring>14 #include <algorithm>15 16 using namespace std;17 18 int dp[15][1005];19 int hire,sal,fire;20 int month[15];21 int n;22 23 int main()24 {25 while(~scanf("%d",&n) && n)26 {27 scanf("%d%d%d",&hire,&sal,&fire);28 int Max = 0;29 for(int i=1; i<=n; i++)30 {31 scanf("%d",&month[i]);32 if(month[i] > Max)33 Max = month[i];34 }35 for(int i=month[1]; i<=Max; i++)36 dp[1][i] = (hire + sal)*i;37 for(int i=2; i<=n; i++)38 {39 for(int j=month[i]; j<=Max; j++)40 {41 dp[i][j] = 0xfffffff;42 for(int k=month[i-1]; k<=Max; k++)43 {44 if(j >= k)45 dp[i][j] = min(dp[i][j],dp[i-1][k]+hire*(j-k)+j*sal);46 else47 dp[i][j] = min(dp[i][j],dp[i-1][k]+fire*(k-j)+j*sal);48 }49 }50 }51 int ans = 0xfffffff;52 for(int i=month[n]; i<=Max; i++)53 if(ans > dp[n][i])54 ans = dp[n][i];55 printf("%d\n",ans);56 }57 return 0;58 }
- hdu 1158 Employment Planning
- hdu 1158 Employment Planning
- HDU 1158 Employment Planning
- HDU 1158 Employment Planning
- HDU 1158 Employment Planning
- HDU 1158 Employment Planning
- hdu 1158 Employment Planning
- hdu 1158 Employment Planning
- HDU 1158 Employment Planning
- HDU 1158 Employment Planning
- HDU 1158 Employment Planning
- hdu 1158 Employment Planning
- hdu 1158 Employment Planning
- HDU 1158 Employment Planning
- hdu 1158 Employment Planning
- hdu 1158 Employment Planning
- hdu 1158 Employment Planning
- hdu 1158 Employment Planning
- HDU 1421 搬寝室
- HDU 1058 & POJ 2247 Humble Number
- HDU 1978 How many ways
- HDU 1081 & POJ 1050 To The Max (最大子矩阵和)
- HDU 2059 龟兔赛跑
- HDU 1158 Employment Planning
- POJ 3070 Fibonacci (矩阵快速幂)
- HDU 1074 Doing Homework (状态压缩DP)
- HDU 2845 Beans
- UIView设置背景图片的方法
- Java陷阱(四)
- android操作文件,保存在手机自带存储上和保存在SD卡上
- U8818 wifi出错!
- 三层架构的 加密 解密功能