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]个人来工作,然后每次雇佣工人需要给一部分钱,每个人每个月还要给工资,如果解雇人还需要给一笔钱,所以问你主管应该怎么雇佣或解雇工人才能使总花销最小 ...
 
随机推荐
- EntityFramwork所有 SSDL 项目都必须以同一提供程序为目标。ProviderManifestToken“2008”不同于以前遇到的“2005”
			
再用spring+mvc+EF搭建框架时,出现这个问题,网上没有找到类似的问题,删除实体重建后莫名其妙的好了,2008指的是连得数据库实例是2008版本的,2005指的是2005版本,出现问题的原因是 ...
 - 好题  线段树对数据的保存+离线的逆向插入 POJ 2887
			
题目大意:给一个字符串,有插入和询问操作,每次往一个位置插入一个字符或者询问第p个位置的字符是什么. 思路:我们离线询问,逆向把所有的字符都插入给线段树,然后再查询就好了,每次都要记得插入线段树的最后 ...
 - Qt多线程编程总结(一)
			
http://blog.csdn.net/mznewfacer/article/details/6965799 QMutex类 一个线程可以锁定互斥量,并且在它锁定之后,其它线程就不能再锁定这个互斥量 ...
 - Inno Setup入门(十九)——Inno Setup类参考(5)
			
: Install Setup 2013-02-02 11:29 377人阅读 评论(0) 收藏 举报 单选按钮 单选按钮在安装中也很常见,例如同一个程序可以选择安装不同的性质的功能,例如选择32位或 ...
 - .net网站报错:对象的当前状态使该操作无效
			
微软在2011年12月29号发布的2011年最后一个更新让哥哥为程序出现的异常头痛了一天. 这个异常在页面数据量小的时候并不会触发,只在页面数据量大的情况下才会出现,开始解决起来让人无从下手,最后才发 ...
 - c++ map unordered_map
			
map operator<的重载一定要定义成const.因为map内部实现时调用operator<的函数好像是const. #include<string> #include& ...
 - zzuli 1907: 小火山的宝藏收益 邻接表+DFS
			
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 113 Solved: 24 SubmitStatusWeb Board Description ...
 - CodeIgniter   如何去掉    Index.php
			
步骤; 1.打开你的WEB服务器的httpd.conf文件. 2.找到LoadModule rewrite_module modules/mod_rewrite.so这行,把该行前的#去掉.保存该文件 ...
 - php  ajax   下拉加载数据
			
视图 <html> <head> <title>健康知识</title> <script type="text/javascript&q ...
 - Arrays类与Array类探究
			
这里所说的Arrays类是util包中的java.util.Arrays,Array是反射包中的java.lang.reflect.Array. 首先介绍Arrays类的常用的静态方法: 1.排序方法 ...