Data Structures & AlgorithmsHardICPC regional · GATE CS top band

Array A = [9, 8, 3, 6, 4, 2, 6] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not ordered) whose values add up to exactly 20.

  1. A. 72
  2. B. 1739
  3. C. 6
  4. D. 128

Correct answer: C. 6

Enumerating all subsets of indices gives 6 with sum 20. Allowing each value to be reused, as in the coin-change count, gives 1739.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic