Calculate the number of string can be formed by this formula in one
statement..

for cross check the result is

2N!/((N+1)! * N!).... where is number of A or B in string



On Thu, Aug 5, 2010 at 8:54 AM, Ashish Goel <[email protected]> wrote:

>
>>
>> void dyckWords(int index, int open, int close)
>> {
>>   static int dyck=0;
>>   if (index == 2 *n)
>>   {
>>     printf("%s\n", out);
>>     return ;
>>   }
>>
>>   out[index] = '('; //or A
>>   if ((open + 1) <= n && open >= close)
>>
>>
>>
>>   {
>>     dyckWords(index + 1, open + 1, close);
>>   }
>>   out[index] = ')';//or B
>>
>>   if ((close + 1) <= n && open >= close)
>>   {
>>     dyckWords(index + 1, open, close + 1);
>>   }
>> }
>>
>>  Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>>
>> On Mon, Jul 19, 2010 at 1:25 AM, Amir hossein Shahriari <
>> [email protected]> wrote:
>>
>>> @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]<algogeeks%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>  --
> 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]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Thanks & Regards

Umesh kewat

-- 
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