hdu1158 Employment Planning

#include <stdio.h>
#define INF 0x3fffff

int dp[15][10002],arr[15];

int main()
{
	int n,i,j,k,min,maxnum,hire,salary,fire;
	while(scanf("%d",&n)&&n)
	{
		scanf("%d %d %d",&hire,&salary,&fire);
		maxnum=0;
		for (i=1;i<=n;i++)
		{
			scanf("%d",&arr[i]);
			if(maxnum<arr[i])
				maxnum=arr[i];
		}
		for(i=arr[1];i<=maxnum;i++)//初始化第一个月
			dp[1][i]=(salary+hire)*i;
		for (i=2;i<=n;i++)
		{
			for (j=arr[i];j<=maxnum;j++)
			{
				min=INF;
				for(k=arr[i-1];k<=maxnum;k++)
					if(min>dp[i-1][k]+(j>=k?(j*salary+hire*(j-k)):(j*salary+(k-j)*fire)))
						min=dp[i-1][k]+(j>=k?(j*salary+hire*(j-k)):(j*salary+(k-j)*fire));
				dp[i][j]=min;
			}
		}
		min=INF;
		for (j=arr[n];j<=maxnum;j++)
		{
			if(min>dp[n][j])
				min=dp[n][j];
		}
		printf("%d\n",min);
	}
	return 0;
}

你可能感兴趣的:(hdu1158 Employment Planning)