Employment Planning

Employment Planning

有n个月,每个月有一个最小需要的工人数量\(a_i\),雇佣一个工人的费用为\(h\),开除一个工人的费用为\(f\),薪水为\(s\),询问满足这n个月正常工作的最小费用,\(n\leq 12\)。

显然可以猜一个结论,因为工人数不确定,猜测每一个月的工人数量必然为某一个月的工人的最小数量,于是可以设\(f[i][j]\)表示前i个月,拥有工人数量\(b_j\)的最小费用,其中\(b\)为\(a\)的离散化数组,因此有

\(f[i][j]=min(min_{k=0}^jf[i-1][k]+(b_j-b_k)\times h,min_{k=j+1}^nf[i-1][k]+(b_k-b_j)\times f)+s\times j\)

这个dp是\(O(n^3)\)的,但是使用单调队列可以优化到\(O(n^2)\),但数据范围没必要。

参考代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define il inline
#define ri register
#define Size 50
using namespace std;
int a[Size],b[Size],dp[Size][Size];
int main(){
    int n,h,s,f;
    while(scanf("%d",&n),n){
        scanf("%d%d%d",&h,&s,&f);
        for(int i(1);i<=n;++i)scanf("%d",&a[i]),b[i]=a[i];
        sort(b+1,b+n+1),memset(dp,0x3f,sizeof(dp)),dp[0][0]=0;
        for(int i(1),j,k;i<=n;++i)
            for(j=0;j<=n;++j)
                if(b[j]>=a[i]){
                    for(k=0;k<=j;++k)
                        dp[i][j]=min(dp[i][j],dp[i-1][k]+(b[j]-b[k])*h+s*b[j]);
                    for(k=j+1;k<=n;++k)
                        dp[i][j]=min(dp[i][j],dp[i-1][k]+(b[k]-b[j])*f+s*b[j]);
                }int ans(0x3f3f3f3f);
        for(int i(0);i<=n;++i)
            ans=min(ans,dp[n][i]);
        printf("%d\n",ans);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/a1b3c7d9/p/11408512.html

时间: 2024-10-14 18:49:03

Employment Planning的相关文章

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

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

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

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

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

hdu1158 Employment Planning(dp)

题目传送门 Employment Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6242    Accepted Submission(s): 2710 Problem Description A project manager wants to determine the number of the workers

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