HDU 1158 dp
来源:互联网 发布:淘宝助理5.6.9 编辑:程序博客网 时间:2024/05/02 00:35
Employment Planning
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4246 Accepted Submission(s): 1776
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
dp[i][j],i为月数,j为人数。对于每个月数枚举所有可能的人数。由上一个月数的人数dp得来。
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int dp[15][10000];int m[15];int main(){ int n; while(scanf("%d",&n)){ if(n == 0) break; int h,c,f; scanf("%d%d%d",&h,&c,&f); int i,j,k,tem; int Max = 0; for(i = 1;i<=n;i++){ scanf("%d",&m[i]); if(m[i]>Max) Max = m[i]; } for(i = m[1];i<=Max;i++) dp[1][i] = (h+c)*i; for(i = 2;i<=n;i++){ for(j = m[i];j<=Max;j++){ int Min = 0x3f3f3f3f; for(k = m[i-1];k<=Max;k++){ if(k>j) tem = dp[i-1][k] + f*(k-j) + c*j; else tem = dp[i-1][k] + h*(j-k) + c*j; if(tem<Min) Min = tem; } dp[i][j] = Min; } } int MIN = 0x3f3f3f3f; for(i = m[n];i<=Max;i++) if(dp[n][i]<MIN) MIN = dp[n][i]; printf("%d\n",MIN); } return 0;}
- hdu 1158 枚举+DP
- hdu 1158(dp)
- hdu 1158 简单dp
- HDU 1158 dp
- HDU 1158 DP
- HDU 1158(dp)
- hdu 1158(DP)
- hdu 1158(dp)
- HDU 1158 dp
- hdu 1158 Employment Planning--DP
- hdu 1158 Employment Planning(DP)
- hdu 1158 Employment Planning(dp)
- hdu 1158 Employment Planning (dp)
- HDU 1158 Employment Planning (DP)
- 【DP】HDU-1158 Employment Planning
- hdu 1158 Employment Planning【dp】
- HDU 1158 Employment Planning dp
- HDU 1158 Employment Planning(dp)
- OpenCV + MFC 鼠标键盘控制截取图像
- mysql5.6 Zip格式配置方法
- hdu2095 find your present (2)(异或)
- Unity3D圣典学习【2】之CharacterController
- WCF实战第一示例
- HDU 1158 dp
- hdoj 3376 Matrix Again and hdoj 2686 Matrix 【最大费用最大流】
- Android UI设计之Color搭配
- 城市选择插件研究(个人研究用——转载至他人文章)
- Java中各种随机字符串生成的方法(亲测)
- cocos2dx3.X shader使图片置灰
- Vs解决方案的目录结构设置和管理
- PAT-A 1064. Complete Binary Search Tree (30)
- 后缀数组(一)