Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional

Array A = [6, 7, 4, 1, 8, 8, 7] (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 18.

  1. A. 128
  2. B. 839
  3. C. 5
  4. D. 50

Correct answer: C. 5

Enumerating all subsets of indices gives 5 with sum 18. Allowing each value to be reused, as in the coin-change count, gives 839.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic