我们有相关的众所周知的问题:
1)分区(决策问题): 给定n个自然数的集合S。是否有可能找到S的子集T,使得T的数量之和等于T \ S的数量之和?
2)分区(一般问题): 给定n个自然数的集合S。假设对此集合的决策问题1)的答案为“是”,则找到这样的子集。
一个简单的问题:如果我们有一个算法可以在多项式时间内求解1),那么如何在多项式时间内求解2)?
答案 0 :(得分:0)
解决方案:假设我们要对n个自然数的集合S进行划分,其和等于数字b,并且我们有一个黑盒算法可以解决多项式时间内的决策问题。
1: If the answer of the partition problem of S is no, then return.
2: Pick an element x of S.
3: If x is equal to b/2 return S\x (partition found).
4. Merge x with another element y of S (set x=x+y and set S=S\y) which is not processed yet.
5: Solve the decision problem for S.
6: If the answer is no then revert step 4, mark y as processed.
7: Go back to step 3.
每次重复步骤2,我们都必须解决多项式时间中的决策问题。由于我们最多只需要重复第2步n-1次,因此总的时间复杂度也是多项式。