HDPJ_1171 Big Event in HDU 解题报告

 Problem Description

Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.
The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0
 

Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 -- the total number of different facilities). The next N lines contain an integer V (0 A test case starting with a negative integer terminates input and this test case is not to be processed.
 

Output
For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.
 

Sample Input

2 10 1 20 1 3 10 1 20 2 30 1 -1
 

Sample Output

20 10 40 40
 
 
解题思路: 也是利用母函数即可求解的题目,只是有点转化而已,改一些内容即可。一般解题的步骤比较固定的。
 
代码如下:
Code:
  1. #include   
  2. using namespace std;  
  3. const int Max1(250005);  
  4. const int Max2(51);  
  5. int num1[Max1];  
  6. int num2[Max1];  
  7. int V[Max2];  
  8. int M[Max2];  
  9. int main ()  
  10. {  
  11.       
  12.     int N;  
  13.     while (cin>>N,N>0)  
  14.     {  
  15.         int sum = 0;   
  16.         for ( int i = 1; i <= N; ++ i )  
  17.         {  
  18.             cin>>V[i]>>M[i];  
  19.             sum += V[i] * M[i];   
  20.         }   
  21.         memset(num1,0,4*sum);  
  22.         memset(num2,0,4*sum);  
  23.         int total = sum;   
  24.         sum /= 2;  
  25.         for (i=0;i<=V[1]*M[1];i+=V[1])  
  26.             num1[i] = 1;   
  27.         for(i=2;i<=N;++i)  
  28.         {  
  29.             for(int j=0;j<=total;++j)  
  30.             {  
  31.                 for(int k=0;k<=V[i]*M[i];k+=V[i])   
  32.                     num2[ j + k ] += num1[j];  
  33.             }    
  34.             for(j=0;j<=total;++j)  
  35.             {  
  36.                 num1[j]=num2[j];  
  37.                 num2[j]=0;   
  38.             }   
  39.         }  
  40.         for (i=sum;i>=0;--i)  
  41.         {  
  42.             if (num1[i]!=0)  
  43.             {  
  44.                 cout<' '<
  45.                 break;  
  46.             }   
  47.         }  
  48.     }  
  49.     return 0;   
  50. }  
 

你可能感兴趣的:(HDOJ)