Given a set of n integers, list all possible subsets with sum>=k

前端 未结 3 1566

Given an unsorted set of integers in the form of array, find all possible subsets whose sum is greater than or equal to a const integer k, eg:- Our set is {1,2,3} and k=2

3条回答
  •  暖寄归人
    2020-12-08 12:48

    Can I use dynamic programming to solve it in polynomial time?

    No. The problem is even harder than @amit (in the comments) mentions. Finding if there exists a subset that sums to a specific k is the subset-sum problem, which is NP-hard. Instead you are asking for how many solutions are equal to a specific k, which is in the much more difficult class of P#. In addition, your exact problem is slightly more difficult since you want to not only count, but enumerate all the possible subsets for k and targets < k.

提交回复
热议问题