HDOJ 1158

Employment Planning

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


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
 
一道比较暴力的DP,居然没有给范围鄙视
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include <string>
#include <stack>
#include <cctype>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>

using namespace std;
//#define Online_Judge
#define outstars cout << "***********************" << endl;
#define clr(a,b) memset(a,b,sizeof(a))
#define lson l , mid  , rt << 1
#define rson mid + 1 , r , rt << 1|1
#define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++)
#define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++)
#define REP(i , x , n) for(int i = (x) ; i > (n) ; i--)
#define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--)
#define mid ((l + r) >> 1)
#define mk make_pair
const int MAXN = 15;
const int maxw = 100 + 20;
const int MAXNNODE = 10000 +10;
const long long LLMAX = 0x7fffffffffffffffLL;
const long long LLMIN = 0x8000000000000000LL;
const int INF = 0x7fffffff;
const int IMIN = 0x80000000;
#define eps 1e-8
#define mod 10007
typedef long long LL;
const double PI = acos(-1.0);
typedef double D;
typedef pair<int , int> pii;
const D e = 2.718281828459;
int dp[MAXN][maxw] , num , aim[MAXN] , hire , fire , salary , maxnum;///dp[i][j]表示第i个月j个员工的最小花费
int main()
{
    //ios::sync_with_stdio(false);
#ifdef Online_Judge
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif // Online_Judge
    int n;
    while(~scanf("%d" , &n) , n)
    {
        scanf("%d%d%d" , &hire , &salary , &fire);
        maxnum = 0;
        FOR(i , 0 , n)
        {
            scanf("%d" ,&aim[i]);
            maxnum = max(maxnum , aim[i]);
        }
        FORR(i , aim[0] , maxnum)dp[0][i] = i * (hire + salary);

        num = 0;
        FOR(i  , 1 , n)
        {
            FORR(j , aim[i] , maxnum)///枚举该月雇多少人
            {
                dp[i][j] = INF;
                FORR(k , aim[i - 1] , maxnum)
                {
                    if(k > j)dp[i][j] = min(dp[i][j] , dp[i - 1][k] + (k - j) * fire + j * salary);///解雇k - j个人
                    else if(k == j)dp[i][j] = min(dp[i][j] , dp[i - 1][j] + j * salary);
                    else dp[i][j] = min(dp[i][j] , dp[i - 1][k] + (j - k) * hire + j * salary);///雇佣j - k个人
                }
            }
        }
        int ans = INF;
        FORR(i , aim[n - 1] , maxnum)ans = min(ans , dp[n - 1][i]);///最后一个月的最小花费
        printf("%d\n" , ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值