Count binary strings with twice zeros in first half | CPP for finding number of binary strings number of '0' in first half is double the number of '0' in second half of string ; pre define some constant ; global values for pre computation ; function to print number of required string ; calculate answer using proposed algorithm ; Driver code
#include <bits/stdc++.h> NEW_LINE #define mod  1000000007 NEW_LINE #define max  1001 NEW_LINE using namespace std ; long long int nCr [ 1003 ] [ 1003 ] ; void preComputeCoeff ( ) { for ( int i = 0 ; i < max ; i ++ ) { for ( int 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 ; } } } long long int computeStringCount ( int N ) { int n = N / 2 ; long long int ans = 0 ; for ( int i = 2 ; i <= n ; i += 2 ) ans = ( ans + ( ( nCr [ n ] [ i ] * nCr [ n ] [ i / 2 ] ) % mod ) ) % mod ; return ans ; } int main ( ) { preComputeCoeff ( ) ; int N = 3 ; cout << computeStringCount ( N ) << endl ; return 0 ; }