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]个人完成工作,问完成整个工作所花费的最少的钱是 ...
随机推荐
- HBase中批量修改
先随便写写..做个随笔记录 使用Rest连接操作Hbase.. 是微软提供的 Microsoft.Hbase.Client 类库.. 版本是0.4.1.0 一直知道 client.StoreCe ...
- IK分词器 整合solr4.7 含同义词、切分词、停止词
转载请注明出处! IK分词器如果配置成 <fieldType name="text_ik" class="solr.TextField"> < ...
- codevs2800 送外卖
题目描述 Description 有一个送外卖的,他手上有n份订单,他要把n份东西,分别送达n个不同的客户的手上.n个不同的客户分别在1~n个编号的城市中.送外卖的从0号城市出发,然后n个城市都要走一 ...
- CentOS6.3编译安装Memcached
要用到如下源码包: /usr/local/src/memcached/libevent-2.0.21-stable.tar.gz /usr/local/src/memcached/memcached- ...
- Shell入门教程:Shell函数的返回值
shell函数返回值一般有3种方式: 1.return语句(默认的返回值) shell函数的返回值可以和其他语言的返回值一样,通过return语句返回. 比如: #!/bin/bash functio ...
- python , angular js 学习记录【1】
1.日期格式化 Letter Date or Time Component Presentation Examples G Era designator Text AD y Year Year 199 ...
- Linux 网络子系统
今天记录一下Linux网络子系统相关的东西. 因为感觉对这一块还是有一个很大的空白,这件事情太可怕了. 摘抄多份博客进行总结一下Linux网络子系统的相关东西. 一. Linux网络子系统体系结构 L ...
- 学习JVM GarbageCollection
前言 Java和C++之间显著的一个区别就是对内存的管理.Java和C++把内存管理的权利赋予给开发人员的方式不同,Java拥有一套自动的内存回收系统(Garbage Collection,GC)简称 ...
- log4Net不能成功生成日志问题(关于配置错误)
log4Net不能成功生成日志问题(关于配置错误) 调试发现问题原因在于 Log4Net IsInfoEnabled 一直为 false,返回的对象中所有 IsXXX 一直为false,这个问题的原 ...
- java8
1:Scanner的使用(了解) (1)在JDK5以后出现的用于键盘录入数据的类. (2)构造方法: A:讲解了System.in这个东西. 它其实是标准的输入流,对应于键盘录入 B:构造方法 Inp ...