logic correctness(STRAB)

Can anyone check my logic for the question How to write a message (http://www.codechef.com/COOK56/problems/STRAB) please. my logic is

  1. count the number of forbidden words(X<S<Y) (=c)[using binary format…A=0,B=1]
  2. find all the words that have these words as substring (=w)[normal combinatorics]
  3. subtract it from 26^n(i.e…26^n-c*w)
    where a^b=pow(a,b)
    is using dp logic compulsory to get the correct answer.what am i missing?