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

  • 相关阅读:
    [Python] Calculate pi With MonteCarlo
    二次函数闭区间求最小值、、
    [2013.10.30 Luogu OJ P1509]找啊找啊找GF
    IE8下绝对居中的margin:auto兼容问题解决办法
    上传文件过长中间显示省略号
    全选
    往textarea中光标所在位置插入文本
    侧栏悬浮窗
    IE火狐兼容小知识点(即时更新)
    排序、添加、删除、上移、下移功能
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/6009472.html
Copyright © 2011-2022 走看看