程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> HDU 1158 Employment Planning (DP)

HDU 1158 Employment Planning (DP)

編輯:C++入門知識

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

Source Asia 1997, Shanghai (Mainland China) 雇傭人:有三項費用:雇傭費(h),工資(w),解雇費(f) 給你n個月需要的人數,求最小的支出費用。。。。。 dp[i][j]:第i天雇傭j個人的費用,確定最大的天數maxn
#include
#include
#include
#include
#include
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]

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved