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]个人完成工作,问完成整个工作所花费的最少的钱是 ...
随机推荐
- 《征服 C 指针》摘录4:函数 与 指针
一.指向函数的指针 函数名可以在表达式中被解读成“指向函数的指针”,因此,正如代码清单 2-2 的实验那样,写成 func 就可以取得指向函数的指针. “指向函数的指针”本质上也是指针(地址),所以可 ...
- css中为了清除浮动经常用到的after样式
.cf:after { display: block; visibility: hidden; width:; height:; line-height:; font-size:; clear: bo ...
- SpringMVC中遇到的Http400 Bad Request 总结
在搭建SpringMVC环境,在使用中遇到了多次Bad Request的连接,下面来总结下. 1.参数类型不对,如后台实体类的属性为int,但传来的参数为字符串 2.因为我的粗心,本来是要通过Ajax ...
- JQuery mobile中按钮自定义属性的改变
1..ui-mobile-viewport是jquery mobile默认给body加的class,这样的话包含选择符优先级高一点 <style> .ui-mobile-viewport ...
- 【转载】实时监听输入框值变化的完美方案:oninput & onpropertychange
oninput 是 HTML5 的标准事件,对于检测 textarea, input:text, input:password 和 input:search 这几个元素通过用户界面发生的内容变化非常有 ...
- 百度地图SDK
百度地图官方SDK文档 http://lbsyun.baidu.com/index.php?title=androidsdk 一.申请百度地图SDK 每一个app对应一个百度地图AK,百度地图 ...
- ecshop中foreach的详细用法归纳
ec模版中foreach的常见用法. foreach 语法: 假如后台:$smarty->assign('test',$test); {foreach from=$test item=list ...
- java6
1:二维数组(理解) (1)元素是一维数组的数组. (2)格式: A:数据类型[][] 数组名 = new 数据类型[m][n]; B:数据类型[][] 数组名 = new 数据类型[m][]; C: ...
- poj2236_并查集_Wireless Network
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 24497 Accepted: 102 ...
- go:windows下用sublime Text搭建go语言开发环境
一.安装 1.安装go go安装包地址:http://pan.baidu.com/s/1hq1mrDM(进入下图中箭头所示目录中下载对应版本) * 注意go的安装路径不能包含中文 ...