Employment Planning DP
Employment Planning
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4782 Accepted Submission(s): 2019
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 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'.
4 5 6
10 9 11
0
状态移动方程: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的更多相关文章
- Hdu 1158 Employment Planning(DP)
Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1158 一道dp题,或许是我对dp的理解的还不够,看了题解才做出来,要加油了. 只能先上代码了 ...
- hdu 1158 dp Employment Planning
Employment Planning Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- 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[HDU1158]
Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 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 ...
- Employment Planning
Employment Planning 有n个月,每个月有一个最小需要的工人数量\(a_i\),雇佣一个工人的费用为\(h\),开除一个工人的费用为\(f\),薪水为\(s\),询问满足这n个月正常工 ...
- HDU 1158 Employment Planning【DP】
题意:给出n个月,雇佣一个人所需的钱hire,一个人工作一个月所需要的钱salary,解雇一个人所需要的钱fire,再给出这n个月每月1至少有num[i]个人完成工作,问完成整个工作所花费的最少的钱是 ...
- HDU 1158 Employment Planning (DP)
题目链接 题意 : n个月,每个月都至少需要mon[i]个人来工作,然后每次雇佣工人需要给一部分钱,每个人每个月还要给工资,如果解雇人还需要给一笔钱,所以问你主管应该怎么雇佣或解雇工人才能使总花销最小 ...
随机推荐
- 简单Spring和mybatis整合配置文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- isset函数
isset (PHP 4, PHP 5) isset — 检测变量是否设置 检测变量是否设置,并且不是 NULL. 如果 var 存在并且值不是 NULL 则返回 TRUE,否则返回 FALSE. $ ...
- VituralBox 虚拟机网路设置 主机无线
主机和虚拟机都关闭防火墙 主机和虚拟机可以互相ping通 主机和虚拟机都可以联网 如果出现 ‘device not managed by NetworkManager’ 错误 network服务器 ...
- 当@PathVariable遇上中文和点
当@PathVariable遇上中文和点 Spring MVC从3.0开始支持REST,而主要就是通过@PathVariable来处理请求参数和路径的映射. 由于考虑到SEO的缘故,很多人喜欢把新闻 ...
- File类与FileInfo类区别
ile类是静态的,FileInfo不是静态的也没有静态的方法,仅可用于实例化的对象.FileInfo方法基本类似于File.关于二者,作何选择. ● 如果仅进行单一方法调用,则可以使用静态File类上 ...
- 工控中的windows
今后的windows如何在工业应用中发展,之前的windows如何保证安全的运行,如果只专注于消费,生产上是否还需要windows,如果那样,windows真的只有windows了
- postfix日志分析pflogsumm
1.pflogsumm功能:统计接收.投递.转发.延时.反弹.拒绝.保留.丢弃的邮件统计发件人和收件人 统计发送和接受方主机/域名 统计SMTPD连接数...... 2.安装# yum install ...
- 快速玩转Apple Pay开发
快速玩转Apple Pay开发 更新时间:2016年02月20日09时25分 来源:传智播客 Apple Pay 2016年2月18日上午,苹果公司宣布,与中国银联达成合作,正式在中国大陆上线Appl ...
- Opencv基础知识-----视频的读取和操作
Opencv读取视频代码 #include "stdafx.h" #include"highgui.h" int main(int argc,char* a ...
- Core Data & MagicalRecord
iOS 本地数据持久化存储: 1.plist 2.归档 3.NSUserDefaults 4.NSFileManager 5.数据库 一.CoreData概述 CoreData是苹果自带的管理数据库的 ...