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;
    }

  • 相关阅读:
    MIPI DIsplay Panel And Linux Driver Model【转】
    Vim|多行行尾插入【转】
    LCD之mipi DSI接口驱动调试流程【转】
    Linux中的DRM 介绍【转】
    linux DRM driver 使用示例【转】
    从零开始写设备树DTS【转】
    linux内核中的宏ffs(x)【转】
    procps工具集 ----Linux中的可用内存指的是什么?【转】
    ps命令交叉编译【转】
    交叉编译Procps-ng-3.3.11【转】
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/6009472.html
Copyright © 2011-2022 走看看