hdu 1158 dp Employment Planning
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
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
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的更多相关文章
- hdu 1158 dp
/* 题目大意:给n个月工作需要的人数,雇佣一个需要花hire 每个月的薪水是salary,解雇一个需要fire 求完成所有工作的最小费用 dp(i,j)表示第i个月雇佣j员工的最小费用 */ #in ...
- HDU 1158 Employment Planning (DP)
题目链接 题意 : n个月,每个月都至少需要mon[i]个人来工作,然后每次雇佣工人需要给一部分钱,每个人每个月还要给工资,如果解雇人还需要给一笔钱,所以问你主管应该怎么雇佣或解雇工人才能使总花销最小 ...
- HDU 1158(非常好的锻炼DP思维的题目,非常经典)
题目链接: acm.hdu.edu.cn/showproblem.php?pid=1158 Employment Planning Time Limit: 2000/1000 MS (Java/Oth ...
- Employment Planning DP
Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu1158 Employment Planning(dp)
题目传送门 Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- HDU1158:Employment Planning(暴力DP)
Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Employment Planning[HDU1158]
Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 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 ...
- Employment Planning
Employment Planning 有n个月,每个月有一个最小需要的工人数量\(a_i\),雇佣一个工人的费用为\(h\),开除一个工人的费用为\(f\),薪水为\(s\),询问满足这n个月正常工 ...
随机推荐
- <LC刷题二>回文字符串判断之leetcode125&234
其他刷题记录见博客首页 1,leecode125 验证回文串 原题: 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. ...
- .NET面试题系列(一)基本概念
什么是CLR CLR常用简写词语,CLR是公共语言运行库(Common Language Runtime)和Java虚拟机一样也是一个运行时环境,它负责资源管理(内存分配和垃圾收集等),并保证应用和底 ...
- 【CodeForces】913 D. Too Easy Problems
[题目]D. Too Easy Problems [题意]给定n个问题和总时限T,每个问题给定时间ti和限制ai,当解决的问题数k<=ai时问题有效,求在时限T内选择一些问题解决的最大有效问题数 ...
- 【POJ】2774 Long Long Message
[题意]给定两个字符串S和T,求最长公共子串.len<=10^5. [算法]后缀自动机 [题解]对字符串S建SAM,然后令串T在S上跑匹配. 这是自动机最原本的功能——匹配,就是串T在SAM(S ...
- 【洛谷 P2553】 [AHOI2001]多项式乘法(FFT)
题目链接 简单处理一下输入,\(fft\)模板题. #include <cstdio> #include <cmath> #include <algorithm> ...
- 【leetcode 简单】第二十二题 对称二叉树
给定一个二叉树,检查它是否是镜像对称的. 例如,二叉树 [1,2,2,3,4,4,3] 是对称的. 1 / \ 2 2 / \ / \ 3 4 4 3 但是下面这个 [1,2,2,null,3,nul ...
- HDU 1754 I Hate It (线段树)
题目链接 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老 ...
- python之yagmail库笔记
1. yagmail是啥 yagmail是给正常人用的,封装的比较彻底的一个python邮件库,发送接收邮件只需要几行代码,炒鸡简单. 2. 安装 使用pip安装,炒鸡简单: pip install ...
- Window 平台安装 Python:
Window 平台安装 Python: 打开WEB浏览器访问http://www.python.org/download/ 在下载列表中选择Window平台安装包,包格式为:python-XYZ.ms ...
- Python3 动态导入模块的两种方式
动态导入模块就是只知道str类型的模块名字符串,通过这个字符串导入模块 需要导入的模块: #!/usr/bin/env python # _*_ coding:utf-8 _*_ # Author:C ...