hdu1171Big Event in HDU(母函数或多重背包)

Big Event in HDU

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33480    Accepted Submission(s): 11649


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
母函数解法:将每一个都当一种物品,拿这些物品来拼成最大值得一半。若不存在,就往下找存在的。
//表达式(1+x^a[i])*(1+x^a[i+1]).....*/ #include using namespace std; #include #include #include #include #include #include int c1[100000],c2[100000]; int a[1001][2],b[100000]; int main() {     int T,i;     while(~scanf("%d",&T))     {         if(T<0)             return 0;         int i,sum=0,j,k,q=0;         for(i=0;i=0;i--)//找出分的最多的质量看存在不。          if(c1[i]==1)           {               printf("%d %d\n",sum-i,i);               break;           }     }     return 0; }
多重背包解法:
#include #include #include using namespace std; #include int a[1000],b[1000],dp[100000]; int main() {    int n;    while(cin>>n)    {        int i,j,k,sum=0;        if(n<0)         return 0;        for(i=0;i>a[i]>>b[i];//a代表体积,b表示质量。            sum+=a[i]*b[i];        }        memset(dp,0,sizeof(dp));        //多重背包的模板        for(i=0;i=a[i];k--)                {                    dp[k]=max(dp[k-a[i]]+a[i],dp[k]);                }            }        }        cout<


 

你可能感兴趣的:(c++,母函数,+,背包)