HDU Employment Planning
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                HDU Employment Planning
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                Employment Planning
Time Limit : 2000/1000ms (Java/Other)???Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 9???Accepted Submission(s) : 7
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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 0Sample Output
199 #include<iostream> using namespace std; int dp[13][100005]; int a[13]; int main() {int n;int i,j,k,min,max;int hire,salary,fire;while(cin>>n,n){max=0;scanf("%d%d%d",&hire,&salary,&fire);for(i=1;i<=n;i++){scanf("%d",&a[i]);if(a[i]>max){max=a[i];}}for(i=1;i<=max;i++){dp[1][i]=i*(hire+salary);}for(i=2;i<=n;i++){for(j=a[i];j<=max;j++){min=10000000;for(k=a[i-1];k<=max;k++){if(k<=j){dp[i][j]=dp[i-1][k]+(j-k)*hire+j*salary;}else{dp[i][j]=dp[i-1][k]+(k-j)*fire+j*salary;}if(dp[i][j]<min){min=dp[i][j];}}dp[i][j]=min;}}min=10000000;for(i=a[n];i<=max;i++){if(dp[n][i]<min){min=dp[n][i];}}cout<<min<<endl;}return 0; }總結(jié)
以上是生活随笔為你收集整理的HDU Employment Planning的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 基于Glodstein枝切法相位解包裹算
- 下一篇: 数据库——(DB、DBMS、SQL)
