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]的更多相关文章

  1. 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 ...

  2. hdu1158 Employment Planning(dp)

    题目传送门 Employment Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  3. HDU1158:Employment Planning(暴力DP)

    Employment Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  4. Employment Planning DP

    Employment Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  5. hdu 1158 dp Employment Planning

    Employment Planning Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  6. Employment Planning

    Employment Planning 有n个月,每个月有一个最小需要的工人数量\(a_i\),雇佣一个工人的费用为\(h\),开除一个工人的费用为\(f\),薪水为\(s\),询问满足这n个月正常工 ...

  7. HDU1158:Employment Planning(线性dp)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1158 这题又是看了题解,题意是一项工作需要n个月完成,雇佣一个人需要m1的钱,一个人的月工资为sa,辞退一 ...

  8. HDU 1158 Employment Planning

    又一次看题解. 万事开头难,我想DP也是这样的. 呵呵,不过还是有进步的. 比如说我一开始也是打算用dp[i][j]表示第i个月份雇j个员工的最低花费,不过后面的思路就完全错了.. 不过这里还有个问题 ...

  9. HDU 1158 Employment Planning【DP】

    题意:给出n个月,雇佣一个人所需的钱hire,一个人工作一个月所需要的钱salary,解雇一个人所需要的钱fire,再给出这n个月每月1至少有num[i]个人完成工作,问完成整个工作所花费的最少的钱是 ...

随机推荐

  1. MYSQL开启慢查询日志实施

    查看当前服务器是否开启慢查询:1.快速办法,运行sql语句show VARIABLES like "%slow%" 2.直接去my.conf中查看.my.conf中的配置(放在[m ...

  2. u盘安装Fedora23

    -2.计划用ultraiso安装 fedora 23 ,然后从windows平台转到Linux平台上. -1.概念理解 硬盘模式:achi(sata) ide (ata) 分区格式:主引导记录(mbr ...

  3. SearchLookUpEdit

    参考资料: 慧都控件网-DevExpress开发资源 在GridControl控件中使用SearchLookUpEdit构建数据快速输入

  4. Anynote 基于ExtJS多用户个人信息管理系统

    Anynote——个人信息管理系统 —–主要用于学习交流—– 源码下载:https://git.oschina.net/xiyt/Anynote.git 一.系统说明 Anynote是一个基于extj ...

  5. rqnoj343 mty的考验

    题目描述 啊!几经周折.mty终于找到了他的偶像.他就是….fyc! 可是fyc这样的高级人士可不喜欢一个人总是缠着他.于是他出了一道难题想考考mty.fyc有几个手下:陈乐天,舒步鸡,胡巍……现在f ...

  6. tyvj1013 找啊找啊找GF

    描述 "找啊找啊找GF,找到一个好GF,吃顿饭啊拉拉手,你是我的好GF.再见.""诶,别再见啊..."七夕...七夕...七夕这个日子,对于sqybi这种单身的 ...

  7. R语言爬虫初尝试-基于RVEST包学习

    注意:这文章是2月份写的,拉勾网早改版了,代码已经失效了,大家意思意思就好,主要看代码的使用方法吧.. 最近一直在用且有维护的另一个爬虫是KINDLE 特价书爬虫,blog地址见此: http://w ...

  8. 【Alpha版本】冲刺总结随笔

    项目预期计划 确定代码规范与编码原则. 根据原型设计,界面设计,搭建应用大致框架,完善控件,背景等的界面设计. 根据体系结构设计,完善界面跳转逻辑,确定功能模块,实现1.0版本功能. 重点完善需求说明 ...

  9. 【安卓】aidl.exe E 10744 10584 io_delegate.cpp:102] Error while creating directories: Invalid argument

    这几天在使用.aidl文件的时候eclipse的控制台总是爆出如下提示: aidl.exe E 10744 10584 io_delegate.cpp:102] Error while creatin ...

  10. 记录一下git 的常用命令

    以后如果要写一个东西,最好先搭建一个本地仓库,用版本控制对其进行操作,可能一开始有一些麻烦,但是很有可能会受益无穷. 说到git,必然会和github联系起来. 不管是在ubuntu里面还是在Wind ...