HDU ACM 1171 Big Event in HDU

Source: Internet
Author: User

Test instructions: give you n different equipment, the value of each device is V, the number of each device is M, please try to divide them into two piles of similar total value, for the value of the two piles is how much, large in front of the output.

Analysis: See many versions on the web, can be used with the mother function, multi-backpack solution, here with 0-1 backpack solution.

Realization: Half of the value of gross position look for the backpack capacity, value for quality, value is also seen as volume; Finally, the value of nearly half of the total value can be found, the other half of the total value minus the half of the value of the backpack, notice that the total value of the backpack can be less than the total value less than half of the value of the


#include <iostream>using namespace Std;int value[5005];int dp[250005];int main () {int N,v,m;int sum,i,j,cnt;while (Cin>>n && n>0) {for (i=0,sum=0,cnt=0;i<n;i++) {cin>>v>>m;while (m--) {value[cnt++]=v;    Sum+=v;}} Memset (Dp,0,sizeof (DP)); for (i=0;i<cnt;i++) for (j=sum/2;j>=value[i];j--) if (dp[j]<dp[j-value[i]]+value[i ]) dp[j]=dp[j-value[i]]+value[i];cout<<sum-dp[sum/2]<< "" <<dp[sum/2]<<endl;} return 0;}


HDU ACM 1171 Big Event in HDU

Related Article

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.