{27, 16, 25, 18, 29}
分割给定集合成两个子集,使其总数之间的差异最小化.
我们可以将给定集合 {27,16,25,18,29} 分成两个子集,通过动态编程解决方案来最小化它们的和数之间的差异.一个解决方案是: - 首先,我们将集合排序为没有减数的顺序,如 `{16,18,25,27,29}`. - 然后,我们可以通过每个元素重复并将其放入子集 1,如果 (子集1 +当前元素的总数) 不等于 [所有元素的总数]/2,否则放入子集 2. - 然后,我们需要找到两个子集的总数之间的绝对差异. 对于输入集合 {27,16,25,18,29} 最小化它们的和数之间的差异的两个子集是:子集 1:16,18,29} 总数为 63.子集 2:25,52 总数为 52 分钟,因此,它们的和数之间的差异是 {16,16,26,26,18,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,2