Data Structures & AlgorithmsModerateGATE CS · Product-company placement

In how many different ways can 'aaaaaa' be split into a sequence of words from the dictionary {a, aa, aaa} (every character used, order kept)?

  1. A. 23
  2. B. 24
  3. C. 25
  4. D. 48

Correct answer: B. 24

ways[i] = Σ ways[j] over dictionary words s[j..i−1], with ways[0] = 1; ways[6] = 24.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic