GATE Computer ScienceHardGATE CS (PYQ pattern)

A + or − sign is placed in front of each of the numbers 1, 1, 2, 3, 5, 8, 13, 21 (the two 1s are different items). In how many ways is the signed total equal to 8?

  1. A. 4
  2. B. 6
  3. C. 8
  4. D. 12

Correct answer: B. 6

Positive items P and negative items N satisfy sum(P) − sum(N) = 8 and sum(P) + sum(N) = 54, so sum(P) = 31. The number of subsets with sum 31 is 6 (subset-sum DP, checked by enumeration).

More Algorithms questions

Exams that ask this topic