# http://acm.nyist.net/JudgeOnline/problem.php?pid=325

#include<iostream>
#include<algorithm>
#include<string.h>
#include<cstdio>
#include<cmath>
using namespace std;
int a[21];
int sum1,sum2, minx;
void dfs(int cur,int n)
{
if(cur==n) minx=min(minx,abs(sum1-sum2));//回溯条件
else{
sum1+=a[cur];
dfs(cur+1,n);
sum1-=a[cur];//回溯时要恢复以前的状态
sum2+=a[cur];
dfs(cur+1,n);
sum2-=a[cur];
}
}
int main()
{
int n;
while(~scanf("%d",&n))
{   minx=0xfffff;
for(int i=0;i<n;++i)
scanf("%d",&a[i]);
sum1=0;sum2=0;
dfs(0,n);
cout<<minx<<endl;
}return 0;
}


#### I/O & Java in ACM

2015-11-08 22:21:51

#### http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=301 (矩阵的用法)

2013-08-08 22:14:22

#### 大一下做题

2017-07-22 21:52:45

#### http://acm.nyist.net/JudgeOnline/problem.php?pid=221

2012-03-29 15:26:59

#### http://acm.nyist.net/JudgeOnline/problem.php?pid=90

2012-03-30 09:52:13

#### http://acm.nyist.net/JudgeOnline/problem.php?pid=129

2011-11-03 11:26:23

#### http://acm.nyist.net/JudgeOnline/problem.php?pid=3

2012-04-13 09:05:26

#### http://acm.nyist.net/JudgeOnline/problem.php?pid=309

2012-03-16 13:59:10

#### http://acm.nyist.net/JudgeOnline/problem.php?pid=267

2012-03-07 20:05:30

#### http://acm.nyist.net/JudgeOnline/problem.php?pid=150

2012-03-28 13:24:18