Data Structures & AlgorithmsModerateGATE CS

In how many different ways can 'abcdabcd' be split into a sequence of words from the dictionary {a, ab, abc, bcd, cd, d, abcd} (every character used, order kept)?

  1. A. 15
  2. B. 17
  3. C. 16
  4. D. 32

Correct answer: C. 16

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic