Employment Planning

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

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
#include<stdio.h>
#include<string.h> const int INF=99999999; int dp[15][10010];
int people[15]; int main()
{
int n;
int h,s,f;
while(~scanf("%d",&n),n)
{
scanf("%d%d%d",&h,&s,&f);
int max_people=0;
int i,j,k;
for(i=1; i<=n; i++)
{
scanf("%d",&people[i]);
if(max_people<people[i])
max_people=people[i];
}
for(i=people[1]; i<=max_people; i++) //初始化第一个月
dp[1][i]=i*s+i*h;
int min;
for(i=2; i<=n; i++)
{
for(j=people[i]; j<=max_people; j++)
{
min=INF; //有了这个前面就不需要用O(n^2)初始化dp了。
for(k=people[i-1]; k<=max_people; k++)
if(min>dp[i-1][k]+(j>=k?(j*s+(j-k)*h):(j*s+(k-j)*f)))
min=dp[i-1][k]+(j>=k?(j*s+(j-k)*h):(j*s+(k-j)*f));
dp[i][j]=min;
}
}
min=INF;
for(i=people[n]; i<=max_people; i++)
if(min>dp[n][i])
min=dp[n][i];
printf("%d\n",min);
}
return 0;
}

hdu 1158 dp Employment Planning的更多相关文章

  1. hdu 1158 dp

    /* 题目大意:给n个月工作需要的人数,雇佣一个需要花hire 每个月的薪水是salary,解雇一个需要fire 求完成所有工作的最小费用 dp(i,j)表示第i个月雇佣j员工的最小费用 */ #in ...

  2. HDU 1158 Employment Planning (DP)

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

  3. HDU 1158(非常好的锻炼DP思维的题目,非常经典)

    题目链接: acm.hdu.edu.cn/showproblem.php?pid=1158 Employment Planning Time Limit: 2000/1000 MS (Java/Oth ...

  4. Employment Planning DP

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

  5. hdu1158 Employment Planning(dp)

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

  6. HDU1158:Employment Planning(暴力DP)

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

  7. Employment Planning[HDU1158]

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

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

  9. Employment Planning

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

随机推荐

  1. Productivity tips, tricks and hacks for academics (2015 edition)

    Productivity tips, tricks and hacks for academics (2015 edition) Contents Jump to: My philosophy: Op ...

  2. 【leetcode 简单】第三十六题 最小栈

    设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈. push(x) -- 将元素 x 推入栈中. pop() -- 删除栈顶的元素. top() -- 获取栈顶元素. ...

  3. LOW逼三人组(三)----插入排序

    插入排序思路 插入排序算法: import random # 随机模块 import time def cal_time(func): # 装饰器 ,用来检测算法所执行的时间 def wrapper( ...

  4. 使用Bash时的几点总结

    作为一个天天与Linux打交道,并以此为生的Linux运维工程师,最常用的工具性语言恐怕就是shell了, 而对于大多数的Linux和一些类Unix而言,其默认的shell就是Bash.使用Bash一 ...

  5. pycharts实现可视化

    https://blog.csdn.net/u012535605/article/details/80677791http://pyecharts.org/#/zh-cn/prepare  (中文官网 ...

  6. python中随机数生成

    1.random.random random.random()用于生成一个0到1的随机符小数: 0 <= n < 1.0 2.random.uniform random.uniform的函 ...

  7. MySQL5.6.26升级到MySQL5.7.9实战方案【转】

    MySQL5.6.26升级到MySQL5.7.9实战方案 转自 MySQL5.6.26升级到MySQL5.7.9实战方案 - 其他网络技术 - 红黑联盟http://www.2cto.com/net/ ...

  8. Freemaker 自定义指令和函数

    自定义函数和指令都可以在前台或者后台进行指定. 个人理解:指令的作用,主要是进行页面调整之后进行输出:函数的作用,主要是为了进行运算,返回运算结果供前台展示. (一) 自定义指令 使用以下格式调用自定 ...

  9. Python连接Access数据库

    前言 今天想要用Python访问Access数据库,折腾了半天,特记录一下 背景 最近想将一些文件记录下来,存入数据库,为此拿LabVIEW写了一个版本,记录环境配置为: LabVIWE:2015 A ...

  10. ACM——【百练习题备忘录】

    1. 在做百练2807题:两倍时,错将判断语句写成 a/b ==2,正确写法是:a == b*2 因为C/C++int型做除法时自动舍入,如:5/2 == 2,但是 5 =/= 2*2. 2. 在做百 ...