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常用命令的英文单词缩写
    Linux常用指令总结
    java exception "file not found or file not exist"
    Linux清空屏幕和清空当前输入的快捷键
    巨蟒python全栈开发-第10天 函数进阶
    为什么不能在函数中给全局变量赋值?
    巨蟒python全栈开发-第9天 初识函数
    巨蟒python全栈开发-第8天 文件操作
    windows10怎样关闭,开机启动项中不需要的应用?
    巨蟒python全栈开发-第7天 基本数据类型补充&深浅拷贝
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/6009472.html
Copyright © 2011-2022 走看看