Nyoj 325 ZB's Birthday

Source: Internet
Author: User

ZB's Birthday

Describe
today is the lunar calendar July early five, ACM team ZB's birthday. ZB is and C small plus, never in Wuhan training. He wanted to buy something for the two brothers to celebrate the birthday, after investigation, ZB found that C small plus and never are very fond of watermelon, and a eat is a bunch of the kind, ZB immediately determined to buy a bunch of watermelon. When he was ready to give the watermelon to C small plus and never, met a problem, never and C small plus not live, can only divide the watermelon into two piles to them, in order to everyone is fair, he wants to let two piles of weight difference is the smallest. The weight of each watermelon is known, can you help him?
Input
multiple sets of test data (<=1500). Data ends with EOF
First line input watermelon number N (1≤n≤20)
The second line has n numbers, W1, ..., and Wn (1≤wi≤10000) represents the weight of each watermelon, respectively.
Output
quality difference After the output is divided into two piles
Sample input
55 8 13) 27 14
Sample output
3

1  2#include <cstdio>3#include <algorithm>4#include <cstring>5 using namespacestd;6 7 Const intinf=999999;8 BOOLFlag;9 inttemp;Ten  One intSum,n,ans; A intused[ +],a[ +]; -  - voidDfsintCurintTotalintnum) the { -     if(cur==num) -     return; -     intTemp=abs (sum-2*Total ); +ans=min (ans,temp); -     if(temp==0|| (total>=sum/2&&temp<=ans)) +     return; ADFS (cur+1, total+a[cur],num); atDFS (cur+1, total,num); - } -  - intMain () - { -     //freopen ("In.txt", "R", stdin); in     inti; -      while(SCANF ("%d", &n)! =EOF) to     { +ans=inf; -          for(sum=0, i=0; i<n;i++) the         { *scanf"%d",&a[i]); $sum+=A[i];Panax Notoginseng         } -memset (Used,0,sizeof(used)); theDfs0,0, n); +printf"%d\n", ans); A     } the     return 0; + } -         

Nyoj 325 ZB's Birthday

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.