题目描述
<p><span style="font-family: ';font-size:10.5pt;'">Consider the partition problem: given a set S of n positive integers, partition it into two disjoint subsets S<sub>1</sub> and S<sub>2</sub> such that the discrepancy</span></p> <p><span style="font-family: ';font-size:10.5pt;'"> E(S) = |sum(S<sub>1</sub>) - sum(S<sub>2</sub>)|<br /> </span></p> <p><span style="font-family: ';font-size:10.5pt;'">is minimized, where sum(S<sub>i</sub>) is <span style="font-family: ';font-size:10.5pt;'">the sum of S<sub>i</sub>'s elements</span>. Design an exhaustive search algorithm for this problem.</span></p>
输入格式
<p>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.</p>
输出格式
<p>For each test data, output the minimum discrepancy of two subsets into which the test data is partitioned.</p>
样例
样例输入 1
10
205
157
133
111
100
91
88
59
47
23
8
635
853
401
868
335
435
704
754
0
样例输出 1
0
3
提交代码
请先登录后提交
🤖 AI 解题助手
DeepSeek
就绪