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. allocator 类

    allcator是一个模板类 定义在memory头文件中,将内存分配与对象构造分开,分配的内存是原始的.未构造的 一.how to use 因其实一个类,则使用allcator时需要首先声明一个类对象 ...

  2. HDU1379:DNA Sorting

    Problem Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries ...

  3. knockout.js

    最近在使用knockout这个JS的MVVM模型,真的很不错,每次去查英文的文档,的确很累的,抽空的时候就把看到的文档按自己的理解翻译一下.当然我不是逐字的翻译. knockout的官方说明:http ...

  4. Google 分布式关系型数据库 F1

    F1是Google开发的分布式关系型数据库,主要服务于Google的广告系统.Google的广告系统以前使用MySQL,广告系统的用户经常需要使用复杂的query和join操作,这就需要设计shard ...

  5. 漫谈QML

    漫谈 QML/Qt Quick QML是从Qt 4.7开始引入的,QML是一种声明语言,使得可以像设计师思考的一样编码,并且Qt Quick元素就是应用程序的编译单元,每一帧的故事板被声明为元素树中的 ...

  6. perl的USE和require

    来源: http://www.cnblogs.com/itech/archive/2010/11/22/1884345.html 相同: 都可以用来引用module(.PM). 不同: 1) 区别在于 ...

  7. flex日期合并与拆分

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  8. spice-vdagent

    The spice-vdagent should be running in the guest. Have you installed the spice guest tools in your w ...

  9. nm applet disable

    http://support.qacafe.com/knowledge-base/how-do-i-prevent-network-manager-from-controlling-an-interf ...

  10. Java 中的四种引用及垃圾回收策略

    Java 中有四种引用:强引用.软引用.弱引用.虚引用: 其主要区别在于垃圾回收时是否进行回收: 1.强引用 使用最普遍的引用.如果一个对象具有强引用,那就 类似于必不可少的生活用品,垃圾回收器绝不会 ...