经典简约
清爽简洁,回归本真
液态水晶
毛玻璃+霓虹光带
赛博朋克
霓虹故障艺术风
🚫
违规操作检测
禁止使用右键菜单
⚠️ 此操作已被系统记录
1

Number Partitioning Problem

📝 题解 🔵 仅限 C++
题目描述
<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;'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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 &lt;= n &lt;= 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
就绪
👋 你好!我是 AI 解题助手。
我已阅读了这道题,可以帮你分析思路、提供代码示例。
⚠️ 请先登录后使用