Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS

A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 10. Two sequences of steps are different if their steps differ in order or kind. In how many ways can the counter reach exactly 10?

  1. A. 55
  2. B. 14
  3. C. 154
  4. D. 77

Correct answer: C. 154

Count with ways[y] += ways[x] for each allowed step from x, in increasing order of x; the total is 154. Leaving out doubling gives 55, and leaving out the +2 step gives 14.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic