dp[i][j] is the number of strings that have i As and j Bs

dp[0][0]=1;   //   s=""
for (i=1;i<=n/2;i++)

dp[i][0]=1;  //   s="AAA..."

for (i=1;i<=n/2;i++)

dp[0][i]=0;  //   the 2nd constraint

for (i=1;i<=n/2;i++)

for (j=1;j<=n/2;j++)

if (j>i)

dp[i][j]=0;     //   the 2nd constraint

else

dp[i][j]=dp[i-1][j]+dp[i][j-1];


dp[n/2][n/2] would be the result

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

Reply via email to