ZB's Birthday

Source: Internet
Author: User

time limit: theMS | Memory Limit:65535KB
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?
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.
quality difference After the output is divided into two piles
Sample input
55 8 13) 27 14
Sample output

#include <stdio.h> #define MAX (A, b) a>b?a:bint a[10000];int sum[10000];int v,ans;void dfs (int i,int cut) {if (i== 0) {Ans=max (ans,cut);        return;} if (ans==v| | Cut+sum[i]<=ans) return, if (CUT+A[I]<=V)//This place is wrong, Cut+a[i]<vdfs (I-1,cut+a[i]);d FS (i-1,cut);} int main () {int n;while (scanf ("%d", &n)!=eof) {ans=0;for (int i=1;i<=n;i++) {scanf ("%d", &a[i]); sum[i]=sum[ I-1]+a[i];} V=sum[n]/2;dfs (N,ans);p rintf ("%d\n", Sum[n]-2*ans);} return 0;}

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

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.