【发布时间】:2014-12-05 18:55:30
【问题描述】:
给定 n ( n
【问题讨论】:
-
我想我来晚了,但这可能会帮助其他来这里的人:techiedelight.com/k-partition-problem-print-all-subsets 存档在这里:web.archive.org/web/20210824071902/https://…
给定 n ( n
【问题讨论】:
一种改进蛮力方法的方法:
s = the sum of all the numbers
for i = 2 to 10
k = s / i
if k is an integer then
Get all partitions of the input array with a minimum subset size of 2 elements and a maximum of n-1 elements.
Check each partition as it's generated to see if all the subsets have the same sum.
end if
next i
硬(和慢)部分是生成分区。您可以使用递归函数来做到这一点。划分 20 个数字应该不会太慢。您可以通过尽早丢弃子集和不相等的分区来优化分区生成。
【讨论】: