Employment Planning

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

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
 
Source
 
 
题意:
有多组数据,每组数据给出一个工程每个月最少需要的工人数量,雇佣工人的花费,每个月的工资,解雇工人的花费,求出最少花费的钱。
题解:
由题意最多十二个月可以无脑暴力DP(测试数据真的很水……),枚举出每个月雇佣最少的人到最多的人的最少花费即可(与上个月的所有情况进行比较)。
状态转移为:
dp[i][f] = min(dp[i][f], dp[i - 1][h] + (f - h) * hire + f * salary);(上个月的人数少于等于need[i]的人数)
dp[i][f] = min(dp[i][f], dp[i - 1][h] + (h - f) * fire + f * salary);(上个月的人数多于need[i]的人数)
具体见代码;
#define _CRT_SECURE_NO_DepRECATE
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cctype>
#include <iterator>
#include <vector>
#include <cstring>
#include <cassert>
#include <map>
#include <queue>
#include <set>
#include <stack>
#define ll long long
#define INF 0x3f3f3f3f
#define ld long double
const ld pi = acos(-.0L), eps = 1e-;
int qx[] = { ,,,- }, qy[] = { ,-,, }, qxx[] = { ,- }, qyy[] = { ,- };
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n;
int hire, salary, fire, need[], dp[][], max, ans;
while (cin >> n && n)
{
memset(dp, , sizeof(dp));
max = ;
ans = INF;
cin >> hire >> salary >> fire;
for (int i = ; i < n; i++)
{
cin >> need[i];
max = ::max(need[i], max);//记录最多需要的人
}
for (int i = need[]; i <= max; i++)//先初始化第一个月需要的钱,枚举从一月最少需要的人到最多需要的人
{
dp[][i] = i * (hire + salary);
}
for (int i = ; i < n; i++)
{
for (int f = need[i]; f <= max; f++)//枚举从最少需要的人到最多需要的人的情况花费的钱
{
dp[i][f] = INF;
for (int h = need[i - ]; h <= max; h++)//与上个月的每种情况进行对比
{
if (h <= f)//人数少于或等于需要的人数
{
dp[i][f] = min(dp[i][f], dp[i - ][h] + (f - h) * hire + f * salary);
}
else//人数多于需要的人数
{
dp[i][f] = min(dp[i][f], dp[i - ][h] + (h - f) * fire + f * salary);
}
}
}
}
for (int i = need[n - ]; i <= max; i++)//找到最小值
{
ans = min(ans, dp[n - ][i]);
}
cout << ans << endl;
}
return ;
}

HDU1158:Employment Planning(暴力DP)的更多相关文章

  1. hdu1158 Employment Planning(dp)

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

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

  3. HDU 1158 Employment Planning【DP】

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

  4. HDU 1158 Employment Planning (DP)

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

  5. hdu 1158 Employment Planning(DP)

    题意: 有一个工程需要N个月才能完成.(n<=12) 给出雇佣一个工人的费用.每个工人每个月的工资.解雇一个工人的费用. 然后给出N个月所需的最少工人人数. 问完成这个项目最少需要花多少钱. 思 ...

  6. Employment Planning[HDU1158]

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

  7. Employment Planning DP

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

  8. hdu 1158 dp Employment Planning

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

  9. Employment Planning

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

随机推荐

  1. webstorm破解 2020 最新更新

    KNBB2QUUR1-eyJsaWNlbnNlSWQiOiJLTkJCMlFVVVIxIiwibGljZW5zZWVOYW1lIjoiZ2hib2tlIiwiYXNzaWduZWVOYW1lIjoiI ...

  2. nes 红白机模拟器 第4篇 linux 手柄驱动支持

    小霸王学习机的真实手柄,实测CPU 占用 80% 接线图: 手柄读时序: joypad.c 驱动: 普通的字符设备驱动. #include <linux/module.h> #includ ...

  3. python3.6 单文件爬虫 断点续存 普通版 文件续存方式

    # 导入必备的包 # 本文爬取的是顶点小说中的完美世界为列.文中的aa.text,bb.text为自己创建的text文件 import requests from bs4 import Beautif ...

  4. Top命令你最少要了解到这个程度

    top命令几乎是每个程序员都会用到的Linux命令.这个命令用来查看Linux系统的综合性能,比如CPU使用情况,内存使用情况.这个命令能帮助我快速定位程序的性能问题. 虽然这个命令很重要,但是之前对 ...

  5. 如何使用Logstash

    目录 一.什么是Logstash 二.如何安装 三.快速使用 四.Input输入插件 五.codec编码插件 六.filter过滤器插件 七.output输出插件 八.总结 一.什么是Logstash ...

  6. Rational Rose 2007破解版

    首先下载好软件,链接在这里 链接:https://pan.baidu.com/s/1op-W-ZX1tqefHffs3m-r0A 提取码:0jwm 这里面包含了Rational Rose 2007版的 ...

  7. 创建和存储 cookie

    在这个例子中我们要创建一个存储访问者名字的 cookie.当访问者首次访问网站时,他们会被要求填写姓名.名字会存储于 cookie 中.当访问者再次访问网站时,他们就会收到欢迎词. 首先,我们会创建一 ...

  8. Python 3.9 新特性:任意表达式可作为装饰器!

    一个月前(2月20日),一则新的 PEP 没有受到任何阻碍就被官方采纳了,这么快的速度,似乎并不多见. 然而,更为高效率的是,仅在半个月内,它的实现就被合入了代码仓.也就是说,我们最快有望在 3 天后 ...

  9. 标题 发布状态 评论数 阅读数 操作 操作 CNN目标检测系列算法发展脉络简析——学习笔记(三):Fast R-CNN

    最近两周忙着上网课.投简历,博客没什么时间写,姑且把之前做的笔记放上来把... 下面是我之前看论文时记的笔记,之间copy上来了,内容是Fast R-CNN的,以后如果抽不出时间写博客,就放笔记上来( ...

  10. 故事:走进JVM的世界(图文并茂)

    注意!本文较长,建议先收藏再阅读.更多文章可以关注作者公众号:码上实战 你也可以 star 我的 GitHub上本文所属仓库:https://github.com/flyhero/MarkNote 说 ...