ZB's Birthday

Source: Internet
Author: User

Description today is the lunar calendar of the beginning of July, 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? Enter multiple sets of test data (<=1500). Data at the end of the first line of EOF input watermelon number n (1≤n≤20) The second line has n number, W1, ..., Wn (1≤wi≤10000) respectively represents the weight of each watermelon output output divided into two piles of quality difference sample input 55 8 13 27 14 Sample Output 3//This is part and  The problem is to compare all the occurrences and statistics, comparing these with the 22 difference. thereby outputting the minimum value. #include <stdio.h> #include <math.h> #include <algorithm>using namespace Std;int a[21],total,n,m;    void Search (int s,int i) {if (i==n) return;   if (Fabs (2*s-total) < m)//part of and is S, then the other part of the and is total-s, while S-(total-s) = = 2*s-total m = fabs (2*s-total);    Update minimum value search (s+a[i],i+1);    Search (s,i+1); return;}    int main () {int i,j;        while (~SCANF ("%d", &n)) {total = 0,m = 999999;            for (i = 0;i<n;i++) {scanf ("%d", &a[i]);        Total + = A[i];        } search (0,0);    printf ("%d\n", m); } return 0;}

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.