5 5 8 13 27 14
3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 |
#include<stdio.h> #define max(a,b) a>b?a:b int
V,ans,n,i,w[21],sum[21]; void
dfs( int
i, int
cnt) { if (i==0) { ans = max(ans,cnt); return ; } if (ans==V||cnt+sum[i]<=ans) return
; if (cnt+w[i]<=V) dfs(i-1,cnt+w[i]); dfs(i-1,cnt); } int
main() { while (~ scanf ( "%d" ,&n)) { ans=0; for ( i=1;i<=n;i++) { scanf ( "%d" ,&w[i]); sum[i]=sum[i-1]+w[i]; } V=sum[n]/2;<br>dfs(n,0); printf ( "%d\n" ,sum[n]-ans*2); } return
0; } |
原文:http://www.cnblogs.com/52Cyan/p/3708768.html