Big Event in HDUTime
limit:5000MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64 U
Description
Nowadays, we all know that computer College are 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's a trouble thing too. All facilities must go halves. First, all facilities is assessed, and the facilities is thought to being same if they has the same value. It is assumed this there is N (0<n<1000) kinds of facilities (different value, different kinds).
Input
Input contains multiple test cases. Each test case is starts with a number n (0 < n <= – The total number of different facilities). The next N lines contain an integer V (0<v<=50--value of facility) and an integer M (0<m<=100--corresponding Number of the facilities) each. You can assume this all V is different.
A test case starting with a negative an integer terminates input and this test case was not the be processed.
Output
For each case, print one line containing integers A and B which denote the value of computer College and software Coll Ege'll get respectively. A and B should be as equal as possible. At the same-time, you should guarantee, which A is not less than B.
Sample Input
210 120 1310 1 20 230 1-1
Sample Output
20 1040 40
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;intdp[250005];intN;intw[50005];intMain () { while(SCANF ("%d", &n)!=eof&&n>=0) {memset (DP,0,sizeof(DP)); intsum=0; intV,num; intCnt=0; for(intI=0; i<n;i++) {scanf ("%d%d",&v,&num); Sum+=num*v; while(num)//separate the same device{w[cnt++]=v; Num--; } } for(intI=0; i<cnt;i++) for(intj=sum/2; j>=w[i];j--) Dp[j]=max (dp[j],dp[j-w[i]]+W[i]); intAns=max (dp[sum/2],sum-dp[sum/2]); printf ("%d%d\n", ans,sum-ans); } return 0;}
HDU1171 (01 backpack sharing problem)