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?
-
-
Input
-
-
Multiple sets of test data (<=). Data at the end of EOF the first line of input watermelon number n (1) The second line has n number, W1, ..., Wn (110000) represents the weight of each watermelon respectively
-
-
Output
-
-
Quality difference after the output is divided into two piles
-
-
Sample input
-
-
5 5 8 - - -
-
-
Sample output
-
3
1 #pragmaComment (linker, "/stack:1024000000,1024000000")2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <math.h>7#include <algorithm>8#include <queue>9#include <Set>Ten#include <bitset> One#include <map> A#include <vector> -#include <stdlib.h> -#include <stack> the using namespacestd; - #definePI ACOs (-1.0) - #defineMax (a) (a) > (b)? (a): (b) - #defineMin (a) (a) < (b)? (a): (b) + #definell Long Long - #defineEPS 1e-10 + #defineMOD 1000000007 A #defineN 1000000 at #defineINF 1e12 - intN; - intA[n]; - intsum; - intans; - voidDfsintCurintnum) { in if(cur==N) { - return; to } + intT=abs (sum-num-num); - if(t<ans) { theans=T; * } $DFS (cur+1, num+a[cur]);Panax NotoginsengDFS (cur+1, num); - } the intMain () + { A while(SCANF ("%d", &n) = =1){ thesum=0; + for(intI=0; i<n;i++){ -scanf"%d",&a[i]); $sum+=A[i]; $ } -ans=inf; -Dfs0,0); theprintf"%d\n", ans); - Wuyi } the return 0; -} View Code
Nyoj 325 ZB's Birthday (DFS)