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. Spring Boot从入门到精通(九)整合Spring Data JPA应用框架

    JPA是什么? JPA全称Java Persistence API,是Sun官方提出的Java持久化规范.是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. ...

  2. 鸡汤 & 毒鸡汤

    1.别低估任何人. 2.你没那么多观众,别那么累. 3.温和对人对事.不要随意发脾气,谁都不欠你的. 4.现在很痛苦,等过阵子回头看看,会发现其实那都不算事. 5.和对自己有恶意的人绝交.人有绝交,才 ...

  3. 今天对C语言不常用的小东西的了解

    今天又翻了C语言的书,看到const语句,一时间想不起来到底是干嘛的,看语句const   int   a=1;明白了这是一个支持常量指定类型的定义常量的关键字,作用几乎与#define一毛一样,但# ...

  4. SpringBoot图文教程17—上手就会 RestTemplate 使用指南「Get Post」「设置请求头」

    有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文教程系列文章目录 SpringBoot图文教程1-Spr ...

  5. java web 中base64传输的坑

    今天在项目中,前端需要向后端发送一张图片,使用toDataURL方法以base64编码的形式传输,在写好程序后,发现报错为base64不是有效的图片,反复排查后发现接口需要一张格式为png的图片,在前 ...

  6. SQL的模糊查询(转载)

    本文由转载而来: 原文地址链接:http://www.cnblogs.com/GT_Andy/archive/2009/12/25/1921914.html 在进行数据库查询时,有完整查询和模糊查询之 ...

  7. Asp.Net Core 3.1 获取不到Post、Put请求的内容 System.NotSupportedException Specified method is not supported

    # 问题 是这样的,我.net core 2.1的项目,读取.获取Post请求内容的一段代码,大概这样: [HttpPost] public async Task<IActionResult& ...

  8. django中的缓存以及跨域

    django中的缓存 先来了解以下问题

  9. Android课程设计——博学谷1.0

    本文讲述了如何应用大三下学期智能移动终端开发技术课程所学知识,完成包含服务器端.客户端程序的应用——博学谷登录模块的开发,结合java语言基本知识,例如:字符串.列表.类.数据库读写等,设计.实现一个 ...

  10. IdentityServer4源码解析_4_令牌发放接口

    目录 identityserver4源码解析_1_项目结构 identityserver4源码解析_2_元数据接口 identityserver4源码解析_3_认证接口 identityserver4 ...