Posted on 2008-04-08 00:18
superman 阅读(313)
评论(0) 编辑 收藏 引用 所属分类:
URAL
Ural can not use <?= operator :(
1 /* Accepted 0.031 200 KB */
2 #include <iostream>
3
4 using namespace std;
5
6 int n, w[20], cnt, best = 0X7FFFFFFF;
7
8 void search(int i, int sum)
9 {
10 if(i == n)
11 return;
12 if(best > abs(cnt - 2 * sum))
13 best = abs(cnt - 2 * sum);
14 search(i + 1, sum);
15 search(i + 1, sum + w[i]);
16 }
17
18 int main()
19 {
20 cin >> n;
21 for(int i = 0; i < n; i++)
22 {
23 cin >> w[i];
24 cnt += w[i];
25 }
26 search(0, 0);
27 cout << best << endl;
28
29 return 0;
30 }
31