Employment Planning[HDU1158]
Employment Planning
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5292 Accepted Submission(s): 2262
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
#include<stdio.h>
#include<string.h> const int INF=; int dp[][];
int people[]; int main(){ //freopen("input.txt","r",stdin); int n;
int hire,salary,fire;
while(scanf("%d",&n) && n){
scanf("%d%d%d",&hire,&salary,&fire);
int max_people=;
int i,j,k;
for(i=;i<=n;i++){
scanf("%d",&people[i]);
if(max_people<people[i])
max_people=people[i];
}
for(i=people[];i<=max_people;i++) //初始化第一个月
dp[][i]=i*salary+i*hire;
int min;
for(i=;i<=n;i++){
for(j=people[i];j<=max_people;j++){
min=INF; //有了这个前面就不需要用O(n^2)初始化dp了。
for(k=people[i-];k<=max_people;k++)
if(min>dp[i-][k]+(j>=k?(j*salary+(j-k)*hire):(j*salary+(k-j)*fire)))
min=dp[i-][k]+(j>=k?(j*salary+(j-k)*hire):(j*salary+(k-j)*fire));
dp[i][j]=min;
}
}
min=INF;
for(i=people[n];i<=max_people;i++)
if(min>dp[n][i])
min=dp[n][i];
printf("%d\n",min);
}
return ;
}
Employment Planning[HDU1158]的更多相关文章
- hdu1158 Employment Planning 2016-09-11 15:14 33人阅读 评论(0) 收藏
Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu1158 Employment Planning(dp)
题目传送门 Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- HDU1158:Employment Planning(暴力DP)
Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Employment Planning DP
Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu 1158 dp Employment Planning
Employment Planning Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- Employment Planning
Employment Planning 有n个月,每个月有一个最小需要的工人数量\(a_i\),雇佣一个工人的费用为\(h\),开除一个工人的费用为\(f\),薪水为\(s\),询问满足这n个月正常工 ...
- HDU1158:Employment Planning(线性dp)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1158 这题又是看了题解,题意是一项工作需要n个月完成,雇佣一个人需要m1的钱,一个人的月工资为sa,辞退一 ...
- HDU 1158 Employment Planning
又一次看题解. 万事开头难,我想DP也是这样的. 呵呵,不过还是有进步的. 比如说我一开始也是打算用dp[i][j]表示第i个月份雇j个员工的最低花费,不过后面的思路就完全错了.. 不过这里还有个问题 ...
- HDU 1158 Employment Planning【DP】
题意:给出n个月,雇佣一个人所需的钱hire,一个人工作一个月所需要的钱salary,解雇一个人所需要的钱fire,再给出这n个月每月1至少有num[i]个人完成工作,问完成整个工作所花费的最少的钱是 ...
随机推荐
- Arcgis SDE10.1 和 Arcgis server10.1的授权文件license
把下面内容复制进空白文本文档,改名和后缀为sde.ecp即可. 3dengine,101,ecp.arcgis.engine,none,WEJDFAZAM5FBAZ8LN115 3dserver,10 ...
- 20145212&20145204信息安全系统实验五
一.实验步骤 1.阅读理解源码 进入/arm2410cl/exp/basic/07_httpd目录,使用 vim编辑器或其他编辑器阅读理解源代码. 2.编译应用程序 运行 make 产生可执行文件 h ...
- ssh保持链接
修改/etc/ssh/sshd_config配置文件 ClientAliveInterval 300(默认为0), 参数的是意思是每5分钟,服务器向客户端发一个消息,用于保持连接,使用service ...
- Android 基础篇(二)
ADB进程 adb指令 adb install xxx.apk adb uninstall 包名 adb devices adb start-server adb kill-server adb sh ...
- Servlet监听器
一.servlet的8个监听器 场景 监听者接口 事件类型 你想知道一个web应用上下文中是否增加.删除或替换了一个属性 javax.servlet.ServletContextAttributeLi ...
- 【bzoj4720】[NOIP2016]换教室
题目描述 对于刚上大学的牛牛来说,他面临的第一个问题是如何根据实际情况申请合适的课程.在可以选择的课程中,有2n节课程安排在n个时间段上.在第i(1≤i≤n)个时间段上,两节内容相同的课程同时在不同的 ...
- PHP变量入门教程(1)基础
基础 PHP 中一个美元符号后面跟上一个变量名称,即表示一个变量.变量的名称是对大小写敏感的. 变量名与 PHP 中其它的标签一样遵循相同的规则.一个有效的变量名由字母或者下划线开头,后面跟上任意数量 ...
- Linux服务器jps报process information unavailable
在Linux下执行 jps 是快速查看Java程序进程的命令,一般情况下hadoop,hbase,storm等进程都是通过jps查看,有些时候因为进程没有被正常结束,比如资源占用过大时挂掉或者没有结束 ...
- ffmpeg-20160901-bin.7z
ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 5 屏幕横向放大 20 像素 6 屏幕横向缩小 20 像素 S 下一帧 [ -2秒 ] +2 ...
- POJ 3155 Hard Life(最大密度子图)
裸题.输入一个无向图,输出最大密度子图(输出子图结点数和升序编号). 看了<最小割模型在信息学竞赛中的应用——胡伯涛>的一部分,感觉01分数规划问题又是个大坑.暂时还看不懂. 参考http ...