zoukankan      html  css  js  c++  java
  • HDU 1158 Employment Planning

    Employment Planning
    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 5191 Accepted Submission(s): 2226


    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)
    解析:DP。
    ``` #include #include #include using namespace std;

    const int INF = 0x3f3f3f3f;
    int n;
    int hire, salary, fire;
    int a[15];
    int dp[15][110]; //dp[i][j]表示到第i个月雇佣j个人为止的最小花费

    void solve()
    {
    memset(dp, INF, sizeof dp);
    dp[0][0] = 0;
    for(int i = 1; i <= n; ++i){
    for(int j = a[i]; j <= 105; ++j){
    for(int k = a[i-1]; k <= 105; ++k){
    int tmp = dp[i-1][k]+salaryj;
    if(j > k)
    tmp += hire
    (j-k);
    else if(j < k)
    tmp += fire*(k-j);
    dp[i][j] = min(dp[i][j], tmp);
    }
    }
    }
    int res = INF;;
    for(int i = a[n]; i <= 105; ++i)
    res = min(res, dp[n][i]);
    printf("%d ", res);
    }

    int main()
    {
    while(scanf("%d", &n), n){
    scanf("%d%d%d", &hire, &salary, &fire);
    for(int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
    solve();
    }
    return 0;
    }

  • 相关阅读:
    【瞎口胡】基础数学 1 快速幂 整除 最大公约数
    【瞎口胡】二分图
    Windos下使用Redis
    VUE的踩坑日记(1)
    公告
    [维度打击]最大连续子序列
    常用函数
    树状数组
    高精度封装
    T4 模板之 单个文件
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/6009472.html
Copyright © 2011-2022 走看看