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. TCP报文首部

    源端口和目的端口,各占2个字节,每个TCP报文段都包含源端口号和目的端口号,用于寻找发送端和接收端的应用进程: 序号,占4个字节,序号用来标识从TCP发送端向TCP接收端发送的数据字节流,它表示在这个 ...

  2. ElasticSearch 6.2.4 实践

    参考资料 ElasticSearch 官网 ElasticSearch,Kibana,Asp.net Core with docker 示例 阮一峰 ElasticSearch 基础概念 索引(ind ...

  3. centeos安装Anconda3

    步骤: #获取安装包 wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.2.0-Linux-x86_64.s ...

  4. GO系列 | 5分钟入门GO【译】

    什么是Google Go? Google Go是由Robert Griesmer,Rob Pike和Ken Thompson在Google设计的一种开源编程语言. Go在语法上类似于C语言: 除了内存 ...

  5. ECNU 计算机系统 (CSAPP) 教材习题作业答案集

    这里是华东师范大学计算机系统的作业答案.由于几乎每一年布置的习题都几乎相同,网上的答案又比较分散,就把自己上学期提交的作业pdf放上来了,供参考. 长这样 Download Link:http://c ...

  6. 使用 Pandas 的 to_excel() 方法来将多个 csv 文件合并到一个 xlsx 的不同 sheets 内

    这几天在用 Python3 研究一个爬虫,最后一个需求是把爬下来的20+个csv文件整合到一个excel表里的不同sheets. 初版的核心代码如下: while year <= 2018: c ...

  7. angular vue通过node启动项目局域网内关闭防火墙无法访问的解决办法

    先试 ng serve --host 0.0.0.0 不行再试 ng serve --host 0.0.0.0 --disable-host-check

  8. Java8 Stream流

    第三章 Stream流 <Java8 Stream编码实战>的代码全部在https://github.com/yu-linfeng/BlogRepositories/tree/master ...

  9. rbac权限(2)

    models.py from django.db import models class User(models.Model): name=models.CharField(max_length=32 ...

  10. 测试leader的职责

    为了项目过程管理更加紧凑,控制项目测试进度.测试质量, 需要指定一个测试leader,测试leader的主要职责是测试边界的划定,整体进度的把控,项目风险识别和应对.具体工作内容如下: 一.需求阶段: ...