HDU 1171 Big Event in HDU (01 backpack)

Source: Internet
Author: User




Big Event in HDUTime limit:10000/5000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 28453 Accepted Submission (s): 10014


Problem Descriptionnowadays, 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).

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 Input
210 120 1310 1 20 230 1-1

Sample Output
20 1040 40


Test instructions, the School of Software and the School of Computer division, as much as possible to make two colleges, as many as the results of the computer college is more than equivalent to the value of the school of Software.


That is, in the case of a space capacity of half the total value, how can make this space load the value of the largest, the maximum value must be less than equal to the total value of half, that is, the value of the final Software Institute. Note that the range of T is greater than or equal to 0, not equal to 1


Code

<pre name= "code" class= "CPP" > #include <iostream> #include <string> #include <cstring> #include <cstdio> #include <algorithm> #include <string> #include <queue> #define MAX1 (b) A>b?a: Busing namespace Std;int num[1008],w[1008];int main () {    int t;    while (~SCANF ("%d", &t), t>=0)    {        int v=0;        for (int i=0; i<t; i++)        {            scanf ("%d%d", &w[i],&num[i]);            V+=w[i]*num[i];        }        int sum=v;        v=v/2.0+0.4;        int dp[200007]= {0};        for (int i=0, i<t; i++)        {while            (num[i]--)            {for                (int j=v; j>=w[i]; j--)                    dp[j]=max1 (dp[j ],dp[j-w[i]]+w[i]);            }        }        Do not find the maximum value, by the above known        //  if (Sum-dp[v]>dp[v])        printf ("%d%d\n", sum-dp[v],dp[v]);//        else//            printf ("%d%d\n", Dp[v],sum-dp[v]);}    }


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 1171 Big Event in HDU (01 backpack)

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.