Data Structures & AlgorithmsModerateGATE CS · Product-company placement

In how many different ways can 'catsanddogs' be split into a sequence of words from the dictionary {cat, cats, and, sand, dog, dogs, s} (every character used, order kept)?

  1. A. 5
  2. B. 7
  3. C. 6
  4. D. 12

Correct answer: C. 6

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic