#3157. Number Partitioning Problem

Number Partitioning Problem

说明

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

提示

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