Data Structures & AlgorithmsHardGATE CS

Using parts 2, 3, 5 (each any number of times), in how many ways can 11 be written as an ORDERED sum (so 1 + 2 and 2 + 1 count separately)?

  1. A. 4
  2. B. 14
  3. C. 20
  4. D. 16

Correct answer: D. 16

Ordered sums: f(n) = Σ f(n − c) over parts c, f(0) = 1, giving 16. Putting the coin loop OUTSIDE the amount loop counts unordered combinations instead (4).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic