@ashish: AAA is the prefix of the string and it is valid as a prefix and
it's only used for strings with length >= 6 (where it is a valid prefix)
actually only dp[i][j] where i==j counts the number of such strings and
otherwise there is no string where i!=j and it that case dp[i][j] counts the
number of valid prefixes for string
dp[0][0]=1 does satisfy both properties because 0=0 so the number of As & Bs
are the same
the logic behind n/2 is that if the length of the string is n this means
that it has n/2 As and n/2 Bs (n must be even)
the dp for n=4 doesn't look like that! this is how it looks (i just compiled
the code and checked values of dp):
1 0 0
1 1 0
1 2 2
so dp[2][2]=2 which means the number of strings with 2 As and 2 Bs is 2

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to