将一组数字分成总数相等的两组
Divide set of numbers into two sets with equal totals
Given a finite sequence of natural numbers. Determine wether it is possible to divide the numbers into two subsets such as totals of both subsets are equal. Show one variant of such distribution. Is there a subset of initial set with total of 100.
我只看到该问题的强力算法 - 检查所有 S(n,2)(第二类斯特林数)组合的总和是否相等,并显示一个这样的组合。并检查初始集合的所有可能组合是否等于 100。是否有更优雅的解决方案?
因为它是一个 NP 完全 Partition Problem there is no polynomial time solution. But if your sum is not big enough then there is an dp solution with complexity O(sum*n)
where n is number of element. Here you can find the solution。
Given a finite sequence of natural numbers. Determine wether it is possible to divide the numbers into two subsets such as totals of both subsets are equal. Show one variant of such distribution. Is there a subset of initial set with total of 100.
我只看到该问题的强力算法 - 检查所有 S(n,2)(第二类斯特林数)组合的总和是否相等,并显示一个这样的组合。并检查初始集合的所有可能组合是否等于 100。是否有更优雅的解决方案?
因为它是一个 NP 完全 Partition Problem there is no polynomial time solution. But if your sum is not big enough then there is an dp solution with complexity O(sum*n)
where n is number of element. Here you can find the solution。