zoukankan      html  css  js  c++  java
  • hdu1158 Employment Planning(dp)

    题目传送门

    Employment Planning

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 6242    Accepted Submission(s): 2710


    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
     
    Recommend
    Ignatius   |   We have carefully selected several similar problems for you:  1227 1074 1080 1024 1078 
    题意:给出n个月,雇佣价钱,工资和辞退价钱;然后给出每个月所需的人数,
            求最小花费
    题解:定义dp[i][j]为以i月份结尾,j个人数的花费最小值
     则dp[i][j]=min{dp[i-1][k]+cost[i][j]};
       其中当k<=j时,cost[i][j]=j*salary+(j-k)*hire;
              k>j时,cost[i][j]=j*salary+(k-j)*fire;
    边界就是 for(int i=people[1];i<=maxn;i++)
            dp[1][i]=i*salary+i*hire;
    #include<iostream>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    #define mod 1000000007
    #define INF 0x3f3f3f3f
    int n;
    int people[13];
    int dp[13][10000];
    int hire,salary,fire;
    int main()
    {
        while(cin>>n)
        {
            if(n==0) break;
            cin>>hire>>salary>>fire;
            int maxn=0;
            for(int i=1;i<=n;i++)
            {
                cin>>people[i];
                maxn=max(maxn,people[i]);
            }
            memset(dp,INF,sizeof(dp));
            for(int i=people[1];i<=maxn;i++)
            dp[1][i]=i*salary+i*hire;
          for(int i=2;i<=n;i++)
          {
              for(int j=people[i];j<=maxn;j++)
              {
                  for(int k=people[i-1];k<=maxn;k++)
                  {
                      if(k<=j)
                      dp[i][j]=min(dp[i][j],dp[i-1][k]+j*salary+(j-k)*hire);
                      else
                      dp[i][j]=min(dp[i][j],dp[i-1][k]+j*salary+(k-j)*fire);
                  }
              }
          }
          int minn=INF;
          for(int i=people[n];i<=maxn;i++)
          {
              minn=min(minn,dp[n][i]);
          }
          cout<<minn<<endl;
        }
        return 0;
    }
  • 相关阅读:
    【转】busybox分析——arp设置ARP缓存表中的mac地址
    【转】OpenWRT开发自定义应用方法
    10大白帽黑客专用的 Linux 操作系统
    原始套接字
    正则表达式
    如何解决虚拟机中的ubuntu系统方向键与退格键不能正常使用的问题
    数组 slice方法和splice方法的区别
    数组去重等数组实例
    JS实现表单全选以及取消全选实例
    JS实现表格隔行变色
  • 原文地址:https://www.cnblogs.com/zhgyki/p/9595420.html
Copyright © 2011-2022 走看看