题目传送门

Employment Planning

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

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
 
Recommend
Ignatius   |   We have carefully selected several similar problems for you:  1227 1074 1080 1024 1078 
题意:给出n个月,雇佣价钱,工资和辞退价钱;然后给出每个月所需的人数,
        求最小花费
题解:定义dp[i][j]为以i月份结尾,j个人数的花费最小值
 则dp[i][j]=min{dp[i-1][k]+cost[i][j]};
   其中当k<=j时,cost[i][j]=j*salary+(j-k)*hire;
          k>j时,cost[i][j]=j*salary+(k-j)*fire;
边界就是 for(int i=people[1];i<=maxn;i++)
        dp[1][i]=i*salary+i*hire;
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define mod 1000000007
#define INF 0x3f3f3f3f
int n;
int people[];
int dp[][];
int hire,salary,fire;
int main()
{
while(cin>>n)
{
if(n==) break;
cin>>hire>>salary>>fire;
int maxn=;
for(int i=;i<=n;i++)
{
cin>>people[i];
maxn=max(maxn,people[i]);
}
memset(dp,INF,sizeof(dp));
for(int i=people[];i<=maxn;i++)
dp[][i]=i*salary+i*hire;
for(int i=;i<=n;i++)
{
for(int j=people[i];j<=maxn;j++)
{
for(int k=people[i-];k<=maxn;k++)
{
if(k<=j)
dp[i][j]=min(dp[i][j],dp[i-][k]+j*salary+(j-k)*hire);
else
dp[i][j]=min(dp[i][j],dp[i-][k]+j*salary+(k-j)*fire);
}
}
}
int minn=INF;
for(int i=people[n];i<=maxn;i++)
{
minn=min(minn,dp[n][i]);
}
cout<<minn<<endl;
}
return ;
}

hdu1158 Employment Planning(dp)的更多相关文章

  1. hdu 1158 Employment Planning(DP)

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

  2. HDU 1158 Employment Planning (DP)

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

  3. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  4. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  5. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  6. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  7. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  8. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  9. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

随机推荐

  1. BJSV-P-002高精度测速一体机

    测速.抓拍.录像于一体,产品处于行业顶尖水平. 1        测速一体机参数 2       接口和资源 3      相机接口 1.       前面板接口 测速一体机镜头接口采用C-Mount ...

  2. java this关键字的用法

  3. Codeforces 958C3 - Encryption (hard) 区间dp+抽屉原理

    转自:http://www.cnblogs.com/widsom/p/8863005.html 题目大意: 比起Encryption 中级版,把n的范围扩大到 500000,k,p范围都在100以内, ...

  4. spark大数据快速分析第二章

    1.驱动程序通过一个SparkContext对象来访问Spark,此对象代表对计算集群的一个连接.shell已经自动创建了一个SparkContext对象.利用SparkContext对象来创建一个R ...

  5. pugixml的使用

    VS项目,头文件处鼠标右键,添加“新建筛选器”,重命名为pugixml,把3个文件添加进来.在用到框架的文件中只需#include"pugixml\pugixml.hpp"即可. ...

  6. C# 批量修改考勤设备时间

    自己工作中用到的小程序,每次远行后批量改一次 如下: 其中的zkemkeeper是中控的相关组件,因是系统组件,须要先注册相关文件后才有效 using System; using System.Col ...

  7. uiautomator python版本

    摘要: 利用jsonrpc技术直接包装uiautomator,调用uiautomator的api在本地直接编写脚本,然后运行测试case,这样比用Java写,然后再打包,runcase要简单的多,关键 ...

  8. Security基础(三):OpenSSL及证书服务、邮件TLS/SSL加密通信

    一.OpenSSL及证书服务 目标: 本案例要求熟悉OpenSSL工具的基本使用,完成以下任务操作: 使用OpenSSL加密/解密文件 搭建企业自有的CA服务器,为颁发数字证书提供基础环境 方案: 使 ...

  9. Python基础教程(016)--Python2和Python3的介绍

    前言 Python2和Python3的区别 内容 Python3是现在和未来的主要版本 Python3没有考虑向下兼容. 官方提供了一个Python过度版本Python2.6 Python2.6及支持 ...

  10. python 中的__str__ 和__repr__方法

    看下面的例子就明白了 class Test(object): def __init__(self, value='hello, world!'): self.data = value >> ...