Count of binary strings of length N having equal count of 0 ' s ▁ and ▁ 1' s | Python3 program to implement the above approach ; Function to calculate C ( n , r ) % MOD DP based approach ; Corner case ; Stores the last row of Pascal 's Triangle ; Initialize top row of pascal triangle ; Construct Pascal 's Triangle  from top to bottom ; Fill current row with the help of previous row ; C ( n , j ) = C ( n - 1 , j ) + C ( n - 1 , j - 1 ) ; Driver Code
MOD = 1000000007 NEW_LINE def nCrModp ( n , r ) : NEW_LINE INDENT if ( n % 2 == 1 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT C = [ 0 ] * ( r + 1 ) NEW_LINE C [ 0 ] = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in range ( min ( i , r ) , 0 , - 1 ) : NEW_LINE INDENT C [ j ] = ( C [ j ] + C [ j - 1 ] ) % MOD NEW_LINE DEDENT DEDENT return C [ r ] NEW_LINE DEDENT N = 6 NEW_LINE print ( nCrModp ( N , N // 2 ) ) NEW_LINE