dynamic programming - Subset Sum : Find subset whose sum greater than K -
i have array of positive integers {a1, a2, ...., an}, , want find out possible subsets of array satisfy following condition:
(sum >= k) where k positive integer. know solution problem dynamic programming, unable think how use case. please help.
p.s. : don't need subsets, product of elements subsets formed.
your problem looks similar 0-1 knapsack problem, except on thing - restriction is, sum must smaller k.
but list problem, restriction is, sum must bigger.
so, example, if find subset, sum of bigger k, add element of set, not included in subset , still answer. let's assume, set {a1, a2, a3, a4} ans sum {a1} >= k. then, have 2^3 ways add a2, a3 , a4 subset.
so, problem looks exponential problem, since need list possible variations.
worst case is, when k = 0. , have n elements greater 0. so, need list 2 ^ n subsets.
probably, link http://en.wikipedia.org/wiki/subset_sum_problem
Comments
Post a Comment