3213 - Number Partitioning Problem
时间限制 : 10 秒
内存限制 : 128 MB
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