题目传送门

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. 奇异值分解基础(SVD)

    最近要了解一下Incremental PCA的一些知识,然后看到一篇论文里面讲到了SVD(奇异值分解),奈何自己以前没有把机器学习的课好好上,现在很多东西还是要补回来.所以,我就想了解一些SVD的基础 ...

  2. 浏览器如何减少 reflow/repaint

    1.不要一条一条地修改 DOM 的样式.与其这样,还不如预先定义好 css 的 class,然后修改 DOM 的 className. 2)把 DOM 离线后修改.如: 使用 documentFrag ...

  3. systemd:在service文件中给Exec传入多个参数

    原问题是这样的: 答案是这样的: 此外在使用prometheus监控mongodb时需要安装prometheus-mongodb-exporter,过程中也发现这种用法: 看看service单元文件是 ...

  4. Linux学习之旅(二)Linux文档操作

    目录操作 1. 创建目录 // 目录可以是绝对路径,也可以是相对路径 mkdir 目录名 //创建一个目录 mkdir -p 目录名1/目录名1/... //一次性创建多级目录 2. 删除目录 // ...

  5. Object.assign()遇到的问题分析

    概念 Object.assign() 方法可以把任意多个的源对象自身的可枚举属性拷贝给目标对象,然后返回目标对象.语法如下: Object.assign(target, ...sources) Obj ...

  6. nyoj 83:迷宫寻宝(二)(计算几何)

    题目链接 枚举所有墙的2n个端点与宝物的位置作为一条线段(墙的端点必定与边界重合), 求出与之相交的最少线段数(判断线段相交时用跨立实验的方法),+1即为结果. #include<bits/st ...

  7. 使用C#获取IP地址方法

    C#中如何获取IP地址?,看到问题的时候我也很纠结,纠结的不是这个问题是如何的难回答,而是纠结的是这些问题都是比较基本的常识,也是大家会经常用到的.但是却不断的有人问起,追根究底的原因估计就是没有好好 ...

  8. mysql8.0.15出错

    昨天装了一个wireshark,一个fiddler,导致晚上项目启动一直报init database出错,卸载了两个软件,还是不行,后来一看mysql服务停止了,但启动总是失败.按照网上的方法好了. ...

  9. 【Linux】设置开机自启

    忘记转发的哪里的. 方法 1这种方法会利用 /etc/ 中的 rc.local 文件来在启动时执行脚本与命令.我们在文件中加上一行来执行脚本,这样每次启动系统时,都会执行该脚本. 不过我们首先需要为 ...

  10. CTF | bugku | 秋名山车神

    ''' @Modify Time @Author ------------ ------- 2019/8/31 19:55 laoalo ''' import requests from lxml i ...