Employment Planning

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4782    Accepted Submission(s): 2019

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
 
参考大牛的题解。
dp[i][j]表示前i个月最后一个月的总人数为j所花的最小费用
 
 
状态移动方程: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的更多相关文章

  1. Hdu 1158 Employment Planning(DP)

    Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1158 一道dp题,或许是我对dp的理解的还不够,看了题解才做出来,要加油了. 只能先上代码了 ...

  2. hdu 1158 dp Employment Planning

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

  3. hdu1158 Employment Planning(dp)

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

  4. HDU1158:Employment Planning(暴力DP)

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

  5. Employment Planning[HDU1158]

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

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

  7. Employment Planning

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

  8. HDU 1158 Employment Planning【DP】

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

  9. HDU 1158 Employment Planning (DP)

    题目链接 题意 : n个月,每个月都至少需要mon[i]个人来工作,然后每次雇佣工人需要给一部分钱,每个人每个月还要给工资,如果解雇人还需要给一笔钱,所以问你主管应该怎么雇佣或解雇工人才能使总花销最小 ...

随机推荐

  1. 概率好题 Light OJ 1027

    题目大意:你在迷宫里,有n扇门,每个门有一个val,这个val可正可负,每次通过一扇门需要abs(x)分钟,如果这个门的val是正的,那么就直接出了迷宫,否则回到原地,问出去迷宫的期望是多少? 思路: ...

  2. 移植 wifi模块

    本文以realtek 8192CU WiFi模块为例,介绍USB wifi在Jelly Bean 4.1的调试笔记. 1.WIFI打不开现象概述 WiFi打不开是指您在UI的settings下选中Wi ...

  3. SQL SERVER中强制类型转换cast和convert的区别

    在SQL SERVER中,cast和convert函数都可用于类型转换,其功能是相同的, 只是语法不同. cast一般更容易使用,convert的优点是可以格式化日期和数值. 代码 select CO ...

  4. servlet多次跳转报IllegalStateException异常

    当发生在如下错误的时候,有一个方案可行, "java.lang.IllegalStateException: Cannot forward after response has been c ...

  5. zTree异步加载并初始化树时全部展开(贴主要代码)

    <%@page pageEncoding="UTF-8"%> <%@include file="/commons/include/html_doctyp ...

  6. web配置文件的<load-on-startup>0</load-on-startup>

    在servlet的配置当中,<load-on-startup>5</load-on-startup>的含义是:标记容器是否在启动的时候就加载这个servlet.当值为0或者大于 ...

  7. [转]Java初始化顺序总结 - 静态变量、静态代码块、成员变量、构造函数

    Java初始化顺序1在new B一个实例时首先要进行类的装载.(类只有在使用New调用创建的时候才会被java类装载器装入)2,在装载类时,先装载父类A,再装载子类B3,装载父类A后,完成静态动作(包 ...

  8. 深入解析FileInputStream和FileOutputStream

    http://swiftlet.net/archives/1363 FileInputStream和FileOutputStream类属于字节类,可以操作任意类型的文件.在数据流的处理过程中,有两种情 ...

  9. elasticsearch 手动控制分片分布

    elasticsearch可以通过reroute api来手动进行索引分片的分配.  不过要想完全手动,必须先把cluster.routing.allocation.disable_allocatio ...

  10. java String不可变对象,但StringBuffer是可变对象

    什么是不可变对象? 众所周知, 在Java中, String类是不可变的.那么到底什么是不可变的对象呢? 可以这样认为:如果一个对象,在它创建完成之后,不能再改变它的状态,那么这个对象就是不可变的.不 ...