"01 Backpack" HDU 1171 Big Event in HDU

Source: Internet
Author: User

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
AuthorlcyThe idea is to first calculate the total value, and then divided by two, so a and B must be closest to the value/2 of a left and right two numbers, with DP[VALUE/2] to do is B,a=value-b
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <cmath>6 using namespacestd;7 8 inta[5005];9 intdp[250005];Ten  One intMain () A { -     intn,v,s,value,value1; -      while(~SCANF ("%d", &n) &&n>=0) the     { -Value=0; -         intj=0; -          for(intI=1; i<=n;i++) +         { -scanf"%d%d",&v,&s); +              while(s--) A             { ata[j]=v; -J + +; -value+=v; -             } -         } -value1=value; inValue/=2; -Memset (DP,0,sizeof(DP)); to          for(intI=0; i<j;i++) +         { -              for(intk=value;k>=a[i];k--) the             { *Dp[k]=max (dp[k],dp[k-a[i]]+a[i]); $             }Panax Notoginseng         } -printf"%d%d\n", value1-Dp[value],dp[value]); the     } +     return 0; A}

"01 Backpack" HDU 1171 Big Event in HDU

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.