Mathematics (JEE)Very hardCodeforces Div2 C

How many words of length 6 over the alphabet {a, b, c} contain neither the substring aa nor the substring bb?

  1. A. 729
  2. B. 239
  3. C. 96
  4. D. 448

Correct answer: B. 239

Let a_n, b_n, c_n count valid words of length n ending in a, b, c: a_n = b_{n-1} + c_{n-1}, b_n = a_{n-1} + c_{n-1}, c_n = a_{n-1} + b_{n-1} + c_{n-1}. Starting from (1,1,1) this gives totals 7, 17, 41, 99 and 239 at length 6.

More Permutations, Combinations and Probability questions

Exams that ask this topic