hdu 1158 Employment Planning

本文探讨了项目管理中如何通过算法确定每月所需员工数量,包括成本核算、员工招聘与解雇策略,以实现项目成本最低化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Employment Planning

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4164    Accepted Submission(s): 1743


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
 

Recommend
Ignatius

正确转移:

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<climits>
#include<queue>
#include<vector>
#include<map>
#include<sstream>
#include<set>
#include<stack>
#include<utility>
//#pragma comment(linker, "/STACK:102400000,102400000")
#define PI 3.1415926535897932384626
#define eps 1e-10
#define sqr(x) ((x)*(x))
#define FOR0(i,n)  for(int i=0 ;i<(n) ;i++)
#define FOR1(i,n)  for(int i=1 ;i<=(n) ;i++)
#define FORD(i,n)  for(int i=(n) ;i>=0 ;i--)
#define  lson   num<<1,le,mid
#define rson    num<<1|1,mid+1,ri
#define MID   int mid=(le+ri)>>1
#define zero(x)((x>0? x:-x)<1e-15)

using namespace std;

const int maxn=1000+20   ;
//const int maxm=    ;
//const int INF=    ;
//typedef long long ll;
const int INF=0x3f3f3f3f;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
//fin.close();
//fout.close();
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);

int dp[14][maxn];
int a[14];
int main()
{
//我从来不贴代码
  int n;int hire,salary,fire;
  while(~scanf("%d",&n)&&n)
  {
      scanf("%d%d%d",&hire,&salary,&fire);
      int maxi=0;
      FOR1(i,n)  scanf("%d",&a[i]),maxi=max(maxi,a[i]);
      a[0]=0;
      for(int i=0;i<=maxi;i++)  dp[0][i]=INF;
      dp[0][0]=0;
      maxi=0;
     for(int i=1;i<=n;i++)
     {
         for(int j=a[i];j<=max(a[i],maxi);j++)
         {
             if(  j>a[i-1] )   dp[i][j]=dp[i-1][a[i-1]]+ hire*(j-a[i-1] )+salary*(j);
             else     dp[i][j]=dp[i-1][a[i-1]]+fire*(a[i-1]-j)+salary*(j);

              for(int k=a[i-1]+1;k<= maxi ;k++)
              {

                  if( j>k  )
                  dp[i][j]=min(dp[i][j],dp[i-1][k]+hire*(j-k)+salary*j);
                  else
                  dp[i][j]=min(dp[i][j],dp[i-1][k]+fire*(k-j)+salary*j);
              }

         }
         maxi=max(a[i],maxi);
     }
     int ans=INT_MAX;
     for(int i=a[n];i<=maxi;i++)
        ans=min(ans,dp[n][i]);
     printf("%d\n",ans);
  }





    return 0;
}

错误转移:

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<climits>
#include<queue>
#include<vector>
#include<map>
#include<sstream>
#include<set>
#include<stack>
#include<utility>
//#pragma comment(linker, "/STACK:102400000,102400000")
#define PI 3.1415926535897932384626
#define eps 1e-10
#define sqr(x) ((x)*(x))
#define FOR0(i,n)  for(int i=0 ;i<(n) ;i++)
#define FOR1(i,n)  for(int i=1 ;i<=(n) ;i++)
#define FORD(i,n)  for(int i=(n) ;i>=0 ;i--)
#define  lson   num<<1,le,mid
#define rson    num<<1|1,mid+1,ri
#define MID   int mid=(le+ri)>>1
#define zero(x)((x>0? x:-x)<1e-15)

using namespace std;

const int maxn=1000+20   ;
//const int maxm=    ;
//const int INF=    ;
//typedef long long ll;
const int INF=0x3f3f3f3f;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
//fin.close();
//fout.close();
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);

int dp[14][maxn];
int a[14];
int main()
{
//我从来不贴代码
  int n;int hire,salary,fire;
  while(~scanf("%d",&n)&&n)
  {
      scanf("%d%d%d",&hire,&salary,&fire);
      int maxi=0;
      FOR1(i,n)  scanf("%d",&a[i]),maxi=max(maxi,a[i]);
      a[0]=0;
      for(int i=0;i<=maxi;i++)  dp[0][i]=INF;
      dp[0][0]=0;
      maxi=0;
     for(int i=1;i<=n;i++)
     {
         for(int j=a[i];j<=max(a[i],maxi);j++)
         {
//             if(  j>a[i-1] )   dp[i][j]=dp[i-1][a[i-1]]+ hire*(j-a[i-1] )+salary*(j);
//             else     dp[i][j]=dp[i-1][a[i-1]]+fire*(a[i-1]-j)+salary*(j);
                dp[i][j]=INF;
         }
         for(int k=a[i-1];k<= maxi ;k++)
        {
            if(  k<=a[i])
                dp[i][a[i]]=min(dp[i][a[i]],dp[i-1][k]+hire*(a[i]-k)+salary*a[i]);
            else if( salary<fire  )
                dp[i][k]=min(dp[i][k],dp[i-1][k]+salary*k);
            else if(salary >fire)
                dp[i][a[i]]=min( dp[i][a[i]],dp[i-1][k]+fire*(k-a[i])+salary*(a[i])   );
            else if(salary==fire)
            {
                for(int left=a[i];left<=k;left++ )
                    dp[i][left]=min(dp[i][left],dp[i-1][k]+fire*(k-left)+salary*left    );
            }
/*
                  if( j>k  )
                  dp[i][j]=min(dp[i][j],dp[i-1][k]+hire*(j-k)+salary*j);
                  else
                  dp[i][j]=min(dp[i][j],dp[i-1][k]+fire*(k-j)+salary*j);*/
        }
         maxi=max(a[i],maxi);
     }
     int ans=INT_MAX;
     for(int i=a[n];i<=maxi;i++)
        ans=min(ans,dp[n][i]);
     printf("%d\n",ans);
  }





    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值