HDU 1158 Employment Planning

题意:有一公司要工作n个月每个月需要至少p[i]个人工作,每个人的工资固定位m,

每雇佣一个人要花费h,每炒掉一个人要花费f。求完成n个月工作,公司最小的花费。

思路: Dp[i][j]为前i个月的留j个人的最优解;p[i]<=j<=Max{p[i]};

j>Max{p[i]}之后无意义,无谓的浪费 记Max_n=Max{p[i]};

Dp[i-1]中的每一项都可能影响到Dp[i],即使p[i-1]<<p[i]

所以利用Dp[i-1]中的所有项去求Dp[i];

对于p[i]<=k<=Max_n,    当k<j时, 招聘;

当k>j时, 解雇 然后求出最小值

Dp[i][j]=min{Dp[i-1][k…Max_n]+(招聘,解雇,工资);

#include<cstdio>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include <queue>
#include <stack>
#include<algorithm>
#include<set>
using namespace std;
#define INF 1e8
#define eps 1e-8
#define ll __int64
#define maxn 100010
#define mol 1000000007
int dp[15][99999];
int main()
{
	int n,h,m,f;
	int p[15];

	while(scanf("%d",&n)&&n)
	{
		scanf("%d%d%d",&h,&m,&f);
		int maxx=0,minn=99999;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&p[i]);
			if(p[i]>maxx)
				maxx=p[i];
			if(p[i]<minn)
				minn=p[i];
		}
		for(int i=0;i<=n;i++)
			for(int j=minn;j<=maxx;j++)
				dp[i][j]=(i==0?0:INF);

		int fire,hire;
		for(int i=1;i<=n;i++)
		{
			for(int j=p[i];j<=maxx;j++)
			{
				if(i==1)
					dp[i][j]=dp[i-1][j]+j*(m+h);
				else
				{

					for(int k=p[i-1];k<=maxx;k++)
					{
						hire=0;fire=0;
						if(k<j)
							hire=(j-k)*h;
						else fire=(k-j)*f;
						dp[i][j]=min(dp[i][j],dp[i-1][k]+hire+fire+j*m);
					}
				}
			}
		}
		int ans=INF;
		for(int i=p[n];i<=maxx;i++)
			if(dp[n][i]<ans) ans=dp[n][i];
		printf("%d\n",ans);
	}
	return 0;
}

HDU 1158 Employment Planning

时间: 2024-10-23 23:28:31

HDU 1158 Employment Planning的相关文章

HDU 1158 Employment Planning (DP)

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 work

Hdu 1158 Employment Planning(DP)

Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1158 一道dp题,或许是我对dp的理解的还不够,看了题解才做出来,要加油了. 只能先上代码了. #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int MAXN = 100 + 28; int dp[15][MAXN]; int workers[

HDU 1158 Employment Planning【DP】

题意:给出n个月,雇佣一个人所需的钱hire,一个人工作一个月所需要的钱salary,解雇一个人所需要的钱fire,再给出这n个月每月1至少有num[i]个人完成工作,问完成整个工作所花费的最少的钱是多少. 用dp[i][j]表示在第i个月雇佣j个人所需要的最少花费 先考虑只解雇人和聘请人的情况 1 for(j=num[i];j<=sum;j++) 2 { 3 if(j>num[i-1])//说明雇佣了人 4 dp[i][j]=dp[i-1][num[i-1]]+j*salary+(j-num

hdu 1158 Employment Planning(DP)

题意: 有一个工程需要N个月才能完成.(n<=12) 给出雇佣一个工人的费用.每个工人每个月的工资.解雇一个工人的费用. 然后给出N个月所需的最少工人人数. 问完成这个项目最少需要花多少钱. 思路: 将(i,num):[第i个月拥有num个工人 ]看成一个状态.那么就想到用DP. 看代码 代码: struct node{ int minNum, maxNum; } month[15]; int n; int hire,salary,fire; int dp[15][505]; int main(

【HDOJ】1158 Employment Planning

简单DP. 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <climits> 5 #define MAXN 105 6 7 int dp[15][MAXN]; 8 int a[15]; 9 10 int getMin(int a, int b) { 11 return a<b?a:b; 12 } 13 14 int main() { 15 int n,

hdu 1158(dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1158 Employment Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3654    Accepted Submission(s): 1502 Problem Description A project manage

zoj 1454 Employment Planning

[题解]: [代码]: 1 #include <iostream> 2 #include <string.h> 3 #include <stdio.h> 4 #include <algorithm> 5 #include <stdlib.h> 6 #define LL long long 7 using namespace std; 8 LL dp[15][100005]; 9 LL N,h,uh,sal,num[15]; 10 LL max(L

HDU1158 Employment Planning 基础DP

Employment Planning 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 ext

Employment Planning[HDU1158]

Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5292 Accepted Submission(s): 2262 Problem DescriptionA project manager wants to determine the number of the workers needed in eve