Count even length binary sequences with same sum of first and second half bits | A Naive Recursive C ++ program to count even length binary sequences such that the sum of first and second half bits is same ; diff is difference between sums first n bits and last n bits respectively ; We can 't cover difference of more  than n with 2n bits ; n == 1 , i . e . , 2 bit long sequences ; First bit is 0 & last bit is 1 ; First and last bits are same ; First bit is 1 & last bit is 0 ; Driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countSeq ( int n , int diff ) { if ( abs ( diff ) > n ) return 0 ; if ( n == 1 && diff == 0 ) return 2 ; if ( n == 1 && abs ( diff ) == 1 ) return 1 ; int res = countSeq ( n - 1 , diff + 1 ) + 2 * countSeq ( n - 1 , diff ) + countSeq ( n - 1 , diff - 1 ) ; return res ; } int main ( ) { int n = 2 ; cout << " Count ▁ of ▁ sequences ▁ is ▁ " << countSeq ( 2 , 0 ) ; return 0 ; }