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?
- A. 4
- B. 6
- C. 8
- 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
- An unbounded knapsack has capacity 47 and item types (weight, value): (5, 11), (8, 19), (9, 20), (13, 29), each available any number of…
- What is the largest sum of an increasing subsequence (strictly increasing, not necessarily contiguous) of [3, 100, 4, 5, 2, 200, 6, 7, 8…
- Two players alternately take a coin from either end of the row 20, 9, 12, 17, 1, 15, 8, 2 (the total is 84) and both play optimally to…
- A stick of length 100 must be cut at positions 20, 35, 50, 70 and 85 (in any order). Each cut costs the length of the piece being cut…
- Balloons with numbers [3, 1, 5, 8, 2, 6] are burst one at a time. Bursting a balloon with neighbours l and r (a missing neighbour counts…
- A directed graph has edges A→B 3, B→C −2, C→D 4, A→C 6, A→D 12, D→E 1, C→E 7, B→E 9. What is the length of the shortest walk from A to E…