time limit: theMS | Memory Limit:65535KB
-
-
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
#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