HDU 1158 Employment Planning (DP)
来源:互联网 发布:狸窝dvd刻录软件 编辑:程序博客网 时间:2024/05/16 13:48
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 610 9 110
Sample Output
199
Source
Asia 1997, Shanghai (Mainland China)
雇佣人:有三项费用:雇佣费(h),工资(w),解雇费(f)
给你n个月需要的人数,求最小的支出费用。
dp[i][j]:第i天雇佣j个人的费用,确定最大的天数maxn
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>using namespace std;int h,w,f;int a[100000];;int dp[15][100000];int main(){ int n,maxn,minn; while(~scanf("%d",&n)&&n) { scanf("%d%d%d",&h,&w,&f); int maxn=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); if(a[i]>maxn) maxn=a[i]; } for(int j=a[1];j<=maxn;j++)//第一天的状态可以确定 dp[1][j]=(h+w)*j; for(int i=2;i<=n;i++) { for(int j=a[i];j<=maxn;j++)//j天雇佣的人数 { minn=INT_MAX; for(int k=a[i-1];k<=maxn;k++)//j的前一天雇佣人数 { if(j>=k) dp[i][j]=(j-k)*h+j*w+dp[i-1][k]; else dp[i][j]=(k-j)*f+j*w+dp[i-1][k]; if(dp[i][j]<minn) minn=dp[i][j]; } dp[i][j]=minn;//取最小值 } } minn=INT_MAX; for(int i=a[n];i<=maxn;i++)//不确定最后一天雇佣了几个人,所以要遍历 { if(dp[n][i]<minn) minn=dp[n][i]; } printf("%d\n",minn); } return 0;}
1 0
- hdu 1158 Employment Planning--DP
- hdu 1158 Employment Planning(DP)
- hdu 1158 Employment Planning(dp)
- hdu 1158 Employment Planning (dp)
- HDU 1158 Employment Planning (DP)
- 【DP】HDU-1158 Employment Planning
- hdu 1158 Employment Planning【dp】
- HDU 1158 Employment Planning dp
- HDU 1158 Employment Planning(dp)
- HDU 1158 Employment Planning DP .
- hdu Employment Planning (dp)
- hdu 1158 Employment Planning (DP)
- hdu 1158 (dp)Employment Planning
- (DP)HDU 1158 Employment Planning
- HDU 1158 Employment Planning (简单二维dp)
- hdu 1158 Employment Planning (dp)
- !HDU 1158 Employment Planning--DP--(二维)
- hdu 1158 Employment Planning
- OC中语法糖,最新语法总结
- MySQL 命令集
- Linux进阶——Linux中查看CPU信息
- Linq查询结果集比对应的sql语句查询结果集不一致,存在重复结果
- OC简便语法 语法糖
- HDU 1158 Employment Planning (DP)
- SQL存储过程实现分页
- 快逸V5数据源配置
- 黑马程序员 java学习笔记(day09)
- hdu 4939 Stupid Tower Defense DP
- 大律法(OTSU法)
- 学习v$sql,v$sqlarea,v$sqltext,v$sqlstats和v$sql_plan
- Struts2笔记四之Ognl
- linux内核线程对信号的处理过程