np-hard证明实例 规约

这里写图片描述

5. Subset sum problem <= Partition problem

问题描述:
        Subset sum problem:given a set (or multiset) of integers T=(t1,t2,⋯,tn), is there a non-empty subset whose sum is k


        Partition problem: partition problem (or number partitioning) is the task of deciding whether a given multiset W of positive integers can be partitioned into two subsets W1 and W2 such that the sum of the numbers in W1 equals the sum of the numbers in W2.


转化过程:

         而且,新添加的两个元素肯定不会同时在W1或W2里,否则二者所在的子集的元素和必定大于二者之和3A>2A。

        2A−k所在的子集的其它元素就是一个满足子集和问题的子集。

7. Partition problem <= Knapsack problem

问题描述:
        Partition problem: partition problem (or number partitioning) is the task of deciding whether a given multiset W of positive integers can be partitioned into two subsets W1 and W2 such that the sum of the numbers in W1 equals the sum of the numbers in W2, i.e.
 

扫描二维码关注公众号,回复: 13717972 查看本文章

        Knapsack problem:Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. 即给定一个物品集合U={u1,u2,⋯,un},且每个物品item有大小s(u)和价值w(u),正整数B(容量)和正数K(价值),是否存在子集U′⊂U使得

        

转化过程:

P的输入转换为Q的输入:

  • 划分问题中的每个数For each t∈W ==> 构造背包问题中一个物品item u 且大小s(u)=价值w(u)=t, 然后对背包容量 B,最小价值K添加如下条件,即等于和的一半

         那么有

         体积符合要求、总价值符合要求,所以是背包问题的解。

Q的输出转换为P的输出:

         因为此时的U'正好等于U的一半,所以划分问题也有解。

P问题、NP问题、NPC问题的概念及实例证明_金良山庄-CSDN博客_np问题举例

猜你喜欢

转载自blog.csdn.net/u013288190/article/details/123450510