Employment planning[hdu1158]

Source: Internet
Author: User

Employment Planning

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 5292 Accepted Submission (s): 2262


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'll be is some extra cost. Once A worker is hired, he'll 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 would confront such a problem:how many workers he'll hire or fire each month in order to keep the Lowes T 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 are 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

#include <stdio.h>#include<string.h>Const intinf=99999999;intdp[ the][10010];intpeople[ the];intMain () {//freopen ("Input.txt", "R", stdin);    intN; intHire,salary,fire;  while(SCANF ("%d", &n) &&N) {scanf ("%d%d%d",&hire,&salary,&Fire ); intmax_people=0; inti,j,k;  for(i=1; i<=n;i++) {scanf ("%d",&People[i]); if(max_people<People[i]) max_people=People[i]; }         for(i=people[1];i<=max_people;i++)//Initialize first monthdp[1][i]=i*salary+i*Hire; intmin;  for(i=2; i<=n;i++){             for(j=people[i];j<=max_people;j++) {min=inf;//with this front there is no need to initialize the DP with O (n^2).                  for(k=people[i-1];k<=max_people;k++)                    if(min>dp[i-1][k]+ (j>=k? ( j*salary+ (j-k) *hire):(j*salary+ (k-j) *Fire)) ) Min=dp[i-1][k]+ (j>=k? ( j*salary+ (j-k) *hire):(j*salary+ (k-j) *Fire )); DP[I][J]=min; }} min=INF;  for(i=people[n];i<=max_people;i++)            if(min>dp[n][i]) min=Dp[n][i]; printf ("%d\n", Min); }    return 0;}
View Code

Employment planning[hdu1158]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.