Employment Planning DP
Employment Planning
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4782 Accepted Submission(s): 2019
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 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'.
4 5 6
10 9 11
0
状态移动方程:dp[i][j] = min{dp[i-1][k] + cost[i][j]},其中cost[i][j]是第i月的花费,
1~当k<=j时,第i个月请了人所以cost[i][j] = j*salary + (j-k)*hire
2~当k>j时,第i个月炒了人,所以cost[i][j] = j*salary + (k-j)*fire
输入时记录了最多需要的人数。
因为他给的是每个月最少需要的人数,所以for(该月需要的最少人数——max_people)而不是for(1——该月需要的最少人数)
直接初始化第一个月。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
int dp[][];
int people[];
void solve(){
int n;
int hire,salary,fire;
while(scanf("%d",&n) == &&n){
scanf("%d%d%d",&hire,&salary,&fire);
int max_people = ;
for(int i = ; i<=n; i++){
scanf("%d",&people[i]);
max_people = max(max_people,people[i]);
}
// memset(dp,INF,sizeof(dp));
for(int i = people[]; i<=max_people; i++){
dp[][i] = (hire+salary)*i;
}
for(int i = ; i<=n; i++){
for(int j = people[i]; j<=max_people; j++){
int minn = INF;
for(int k = people[i-]; k<=max_people; k++){
int cost = k<=j?(salary*j+(j-k)*hire):(salary*j+(k-j)*fire);
minn =min(minn,(dp[i-][k] + cost));
}
dp[i][j] = minn;
}
}
int ans = INF;
for(int j = people[n]; j<=max_people; j++) ans = min(ans,dp[n][j]);
printf("%d\n",ans);
}
}
int main()
{
solve();
return ;
}
Employment Planning DP的更多相关文章
- Hdu 1158 Employment Planning(DP)
Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1158 一道dp题,或许是我对dp的理解的还不够,看了题解才做出来,要加油了. 只能先上代码了 ...
- hdu 1158 dp Employment Planning
Employment Planning Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- 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[HDU1158]
Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 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 ...
- Employment Planning
Employment Planning 有n个月,每个月有一个最小需要的工人数量\(a_i\),雇佣一个工人的费用为\(h\),开除一个工人的费用为\(f\),薪水为\(s\),询问满足这n个月正常工 ...
- HDU 1158 Employment Planning【DP】
题意:给出n个月,雇佣一个人所需的钱hire,一个人工作一个月所需要的钱salary,解雇一个人所需要的钱fire,再给出这n个月每月1至少有num[i]个人完成工作,问完成整个工作所花费的最少的钱是 ...
- HDU 1158 Employment Planning (DP)
题目链接 题意 : n个月,每个月都至少需要mon[i]个人来工作,然后每次雇佣工人需要给一部分钱,每个人每个月还要给工资,如果解雇人还需要给一笔钱,所以问你主管应该怎么雇佣或解雇工人才能使总花销最小 ...
随机推荐
- 第一个WebAPI项目
(1)新建一个ASP.NET MVC项目,取名为:MyMvcWebAPIDemo,项目类型选择WebAPI. (2)在Models中新增一个类,取名为:Product,作为我们要测试的实体模型. ...
- 20150627分享iOS开发笔记
util是工具的意思:Ad Hoc是特别的,临时的意思;validate是验证的意思: 打包 苹果的键盘真好使 6和6 plus真机测试报错:No architectures to compile f ...
- VG、LV、rezise2fs、lvresize、fuer使用说明
南沙节点改变LV大小,参考鸟哥第 570页 1.# resize2fs /dev/mapper/vg_niotsvr3-lv_home 150G resize2fs 1.41.12 (17-May-2 ...
- Video Cards
Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- iOS8中的动态文本
原文链接 : Swift Programming 101: Mastering Dynamic Type in iOS 8 原文作者 : Kevin McNeish Apple声称鼓励第三方App能够 ...
- POJ2299--树状数组求逆序数
Description In this problem, you have to analyze a particular sorting algorithm. The algorithm proce ...
- CenOS配置VSFTP服务器
1 Linux FTP服务器分类: wu-ftp proftp=profession ftp vsftp=very security ftp 2 安装vsftp yum install vsftp 3 ...
- Java学习之位运算符
位运算符:&,|,^,~,<<,>> & (按位与):只有对应的两个二进制位均为1时,结果才为1.例如,9&5,即00001001&000001 ...
- android:editable is deprecated: Use an <EditText> to make it editable
问题:android:editable is deprecated: Use an to make it editable 意思:Android的:编辑是反对:使用<</span> ...
- (转)Windows管道(Pipe)重定向stdout,stderr,stdin
参考: http://qiusuoge.com/11496.html http://www.cnblogs.com/BoyXiao/archive/2011/01/01/1923828.html st ...