Count binary strings with twice zeros in first half | pre define some constant ; global values for pre computation ; function to print number of required string ; calculate answer using proposed algorithm ; Driver code
var mod = 1000000007 var max = 1001 var nCr = Array . from ( Array ( 1003 ) , ( ) => Array ( 1003 ) ) ; function preComputeCoeff ( ) { for ( var i = 0 ; i < max ; i ++ ) { for ( var j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) nCr [ i ] [ j ] = 1 ; else nCr [ i ] [ j ] = ( nCr [ i - 1 ] [ j - 1 ] + nCr [ i - 1 ] [ j ] ) % mod ; } } } function computeStringCount ( N ) { var n = N / 2 ; var ans = 0 ; for ( var i = 2 ; i <= n ; i += 2 ) ans = ( ans + ( ( nCr [ n ] [ i ] * nCr [ n ] [ i / 2 ] ) % mod ) ) % mod ; return ans ; } preComputeCoeff ( ) ; var N = 3 ; document . write ( computeStringCount ( N ) ) ;