标签:
5 5 8 13 27 14
3
#include<cstdio> #include<cmath> const int MAXN = 0x7ffff; int tot, Min; int a[25]; void dfs(int sum, int right) { if(right<0) return; if(abs(tot-2*sum)<Min) Min = abs(tot-2*sum); dfs(sum+a[right], right-1); dfs(sum, right-1); } int main() { int n; while(scanf("%d", &n)!=EOF) { Min = MAXN; tot = 0; for(int i=0; i<n; i++) { scanf("%d", &a[i]); tot+=a[i]; } dfs(0, n-1); printf("%d\n", Min); } return 0; }
标签:
原文地址:http://www.cnblogs.com/acm1314/p/4746806.html