Subsets of a given Set of Integers whose sum is a Constant N : Java

后端 未结 2 1340
旧时难觅i
旧时难觅i 2021-01-28 11:09

Given a set of integers, how to find a subset that sums to a given value...the subset problem ?

Example : S = {1,2,4,3,2,5} and n= 7 Finding the possible subsets whose s

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-28 12:07

    In three steps:

    1. Find the powerset of S (the set of all subsets of S)

    2. Compute the sum of each subset

    3. Filter out subsets that did not sum to 7.

提交回复
热议问题