Big Event in HDU
|
Time limit:10000/5000 MS (java/others) Memory limit:65536/32768 K (java/others) |
Total submission (s): 1139 Accepted Submission (s): 444 |
|
problem descriptionnowadays, we all know this computer College is the biggest DEPA Rtment 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). |
Inputinput 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.
|
Outputfor, print one line containing, integers A and B which denote the value of computer College and Softwar e College'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 Input210 120 1310 1 20 230 1-1
|
Sample Output20 1040 40
|
Authorlcy |
This is the subject of a multi-pack (the original value of the item is the value and cost of putting the item in the backpack, as it does not exceed the backpack capacity and the maximum value, which is the closest to the backpack capacity), that is, the original value of these items and the closest to the backpack capacity. Look at half of the total value of the item as a backpack capacity.
Here's one of the weirdest eight elder brothers I've ever seen ... Sweat...
This problem is a negative number as the end sign of the input, and not only limited to-1, by the inertia of the thinking pit ....
Code:
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6 using namespacestd;7 Const intmaxn=250010;8 Const intinf=99999999;9 intV[MAXN];Ten intDP[MAXN]; One intnum[ -]; A intMain () - { - //freopen ("data.in", "R", stdin); theStd::ios::sync_with_stdio (false); -Std::cin.tie (0); - intN; - intsum; + intcc; - while(cin>>n&&n>=0){ +sum=0; AMemset (DP,0,sizeof(DP)); at for(intI=0; i<n;i++){ -Cin>>v[i]>>Num[i]; -sum+= (v[i]*num[i]); - } -cc=sum/2; - for(intI=0; i<n;i++){ in for(intk=0; k<num[i];k++){ - for(intj=cc;j>=v[i];j--){ toDp[j]=max (dp[j],dp[j-v[i]]+v[i]); + } - } the } *cout<<sum-dp[cc]<<" "<<dp[cc]<<Endl; $ }Panax Notoginseng}
Hdu1171--big Event in HDU (multiple backpack)