博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1158 Employment Planning (DP)
阅读量:5268 次
发布时间:2019-06-14

本文共 2696 字,大约阅读时间需要 8 分钟。

Employment Planning

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

Total Submission(s): 2110    Accepted Submission(s): 832

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——该月需要的最少人数)
 
直接初始化第一个月。
View Code
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; //Constant Declaration /*--------------------------*/ //#define LL long long #define LL __int64 const int M=10000; const int INF=1<<30; const double EPS = 1e-11; const double PI = acos(-1.0); /*--------------------------*/ // some essential funtion /*----------------------------------*/ void Swap(int &a,int &b){ int t=a;a=b;b=t; } int Max(int a,int b){ return a>b?a:b; } int Min(int a,int b){ return a
dp[i-1][k] + (j>=k?(j*salary+hire*(j-k)):(j*salary+fire*(k-j)))) { minn = dp[i-1][k] + (j>=k?(j*salary+hire*(j-k)):(j*salary+fire*(k-j))); } } dp[i][j] = minn; } } int min = INF; for (j = people[n]; j <= max_people; j++) { if (min > dp[n][j]) { min = dp[n][j]; } } printf("%d\n", min); } return 0; }

转载于:https://www.cnblogs.com/qiufeihai/archive/2012/03/16/2400273.html

你可能感兴趣的文章
java 常用命令
查看>>
51nod1076 (边双连通)
查看>>
Linux pipe函数
查看>>
java equals 小记
查看>>
2019春 软件工程实践 助教总结
查看>>
Zerver是一个C#开发的Nginx+PHP+Mysql+memcached+redis绿色集成开发环境
查看>>
java实现哈弗曼树
查看>>
程序的静态链接,动态链接和装载 (补充)
查看>>
关于本博客说明
查看>>
HDU 2548 A strange lift
查看>>
Linux服务器在外地,如何用eclipse连接hdfs
查看>>
react双组件传值和传参
查看>>
[Kaggle] Sentiment Analysis on Movie Reviews
查看>>
价值观
查看>>
mongodb命令----批量更改文档字段名
查看>>
MacOS copy图标shell脚本
查看>>
国外常见互联网盈利创新模式
查看>>
Oracle-05
查看>>
linux grep 搜索查找
查看>>
Not enough free disk space on disk '/boot'(转载)
查看>>