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(LL a,LL b){
11 if (a>b) return a;else return b;
12 }
13 LL min(LL a,LL b){
14 if (a<b) return a;else return b;
15 }
16 int main(){
17 while(cin>>N && N>0){
18 cin>>h>>sal>>uh;
19 int MaxN=-1;
20 for(int i=1;i<=N;i++) {
21 cin>>num[i];
22 MaxN=max(MaxN,num[i]);
23 }
24 for(int i=0;i<=N;i++){
25 for(int j=0;j<=MaxN;j++) dp[i][j]=99999999;
26 }
27 for(int i=num[1];i<=MaxN;i++) dp[1][i]=i*(h+sal);
28 for(int i=2;i<=N;i++){
29 for(int j=num[i];j<=MaxN;j++){
30 for(int k=0;k<=MaxN;k++){
31 if (k<num[i-1]) continue;
32 if (k==j) dp[i][j]=min(dp[i][j],dp[i-1][k]+sal*j);
33 if (k<j) dp[i][j]=min(dp[i][j],dp[i-1][k]+sal*j+h*(j-k));
34 if (k>j) dp[i][j]=min(dp[i][j],dp[i-1][k]+sal*j+uh*(k-j));
35 }
36 // cout<<"i="<<i<<","<<"j="<<j<<":" ;
37 // cout<<dp[i][j]<<endl;
38 }
39 }
40 int ans=99999999;
41 for(int i=num[N];i<=MaxN;i++) ans=min(ans,dp[N][i]);
42 cout<<ans<<endl;
43 }
44 return 0;
45 }

//错误是注意检查初值、边界

zoj 1454 Employment Planning,布布扣,bubuko.com

时间: 2024-10-09 04:22:10

zoj 1454 Employment Planning的相关文章

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

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

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