
Here we will see all possible binary numbers of n bit (n is given by the user) where the sum of each half is same. For example, if the number is 10001 here 10 and 01 are same because their sum is same, and they are in the different halves. Here we will generate all numbers of that type.
Algorithm
genAllBinEqualSumHalf(n, left, right, diff)
left and right are initially empty, diff is holding difference between left and right
Begin
if n is 0, then
if diff is 0, then
print left + right
end if
return
end if
if n is 1, then
if diff is 0, then
print left + 0 + right
print left + 1 + right
end if
return
end if
if 2* |diff| <h2>Example</h2><pre class="brush:php;toolbar:false;">#include <bits>
using namespace std;
//left and right strings will be filled up, di will hold the difference between left and right
void genAllBinEqualSumHalf(int n, string left="", string right="", int di=0) {
if (n == 0) { //when the n is 0
if (di == 0) //if diff is 0, then concatenate left and right
cout <h2>输出</h2>
<pre class="brush:php;toolbar:false;">100001
100010
101011
110011
100100
101101
101110
110101
110110
111111











