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

  • 相关阅读:
    防止表单重复提交的几种策略
    Linux模块
    ASP.Net MVC3 图片上传详解(form.js,bootstrap)
    在ASP.NET MVC3 中利用Jsonp跨域访问
    C# 利用反射动态创建对象——带参数的构造函数和String类型
    第一章 CLR 的执行模型
    Linux Shell脚本攻略 读书笔记
    使用MVC4,Ninject,EF,Moq,构建一个真实的应用电子商务SportsStore
    验证码识别的一些总结及相关代码
    使用DateTime的ParseExact方法实现特殊日期时间的方法详解(转)
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/6009472.html
Copyright © 2011-2022 走看看