6705: Number Partitioning Problem

内存限制:128 MB 时间限制:10.000 S
评测方式:文本比较 命题人:
提交:4 解决:3

题目描述

Consider the partition problem: given a set S of n positive integers, partition it into two disjoint subsets S1 and S2 such that the discrepancy

                            E(S) = |sum(S1) - sum(S2)|

is minimized, where sum(Si) is the sum of Si's elements. Design an exhaustive search algorithm for this problem.

输入

Input includes multiple groups of data. The first line of each group of data is an integer n (10 <= n <= 20). n = 0 means that the input is over. Each of the next n lines has an integer which belongs to a set to be partitioned.

输出

For each test data, output the minimum discrepancy of two subsets into which the test data is partitioned.

样例输入 复制

10
205
157
133
111
100
91
88
59
47
23
8
635
853
401
868
335
435
704
754
0

样例输出 复制

0
3

提示

原样例数据超出范围,予以更新。