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

- count the number of forbidden words(X<S<Y) (=c)[using binary format…A=0,B=1]
- find all the words that have these words as substring (=w)[normal combinatorics]
- 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?