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. Java的生日

    你知道巴西的税务系统,亚马逊的Kindle阅读器以及韩国的第一大镁板制造厂有什么共同点吗?乍一看上去,这简直就是风马牛不相及,但是这些系统同世界上其它100亿个设备共享一个元素,那就是Java. 19 ...

  2. 第二轮冲刺-Runner站立会议05

    今天:将baseadapter的原理弄清楚了 明天:解决适配问题 困难:程序会停止运行

  3. Node.js入门笔记(6):web开发方法

    使用node进行web开发 用户上网流程: 表面上看:打开浏览器--输入网址--跳转--上网. 背后的过程是什么呢? http请求网址到指定的主机--服务器接收请求--服务器响应内容到用户浏览器--浏 ...

  4. JS策略模式

    1.策略模式的定义 策略模式又叫算法簇模式,将一组算法分装到一组具体共同接口的独立类或者对象中,它不影响客户端的情况下发生变化. 通常策略模式适用于当一个应用程序需要实现一种特点的服务和功能,而且该程 ...

  5. sublime2使用jshint

    合理配置Jshint可以帮助写出高质量的代码,通过sublime2插件 JSHint Gutter 可以迅速提供开发效率和减少bug的个数. 1.安装JSHint Gutter插件 sublime2按 ...

  6. 【Tomcat】tomcat报连接超时错误

    程序一直报这个错误 [getui-server][ERROR] [2016-03-17 10:50:00] getui.task.HftMongoInfoTask.execute(137) | --H ...

  7. 【相当实用】如何让TortoiseSVN导出新增或修改过的文件

    当一个网站项目进入运营维护阶段以后,不会再频繁地更新全部源文件到服务器,这个时间的修改大多是局部的,因此更新文件只需更新修改过的文件,其他没有修改过的文件就没有必要上载到服务器.但一个稍微上规模的网站 ...

  8. 自定义PHP系统异常处理类

    <?php // 自定义异常函数 set_exception_handler('handle_exception'); // 自定义错误函数 set_error_handler('handle_ ...

  9. 《征服 C 指针》笔记6:练习——挑战那些复杂的声明

    应该是小试牛刀的时候了. 在 ANSI C 的标准库中,有一个 atexit()函数.如果使用这个函数,当程序正常结束的时候,可以回调一个指定的函数. atexit()的原型定义如下: int ate ...

  10. H5案例分享:移动端touch事件判断滑屏手势的方向

    移动端touch事件判断滑屏手势的方向 方法一 当开始一个touchstart事件的时候,获取此刻手指的横坐标startX和纵坐标startY: 当触发touchmove事件时,在获取此时手指的横坐标 ...