// L-23 MCS 360 Fri 15 Oct 2010 : enumerate_bits

/* With a recursive function we enumerate all bit combinations.
   This corresponds to enumerating all subsets of a set of n elements:
   zero at the k-th position means we do not take the kth element, a one
   at the k-th position indidcates the subset contains the kth element. */

#include <iostream>
#include <vector>
using namespace std;

void enumerate_bits ( int k, int n, vector<bool> &a );
// enumerates all combinations of n bits,
// starting at k (call with k = 0),
// accumulates the result in the boolean vector a.

int main()
{
   cout << "give number of bits : ";
   int n; cin >> n;

   vector<bool> v;
   for(int i=0; i<n; i++) v.push_back(false);

   enumerate_bits(0,n,v);

   return 0;
}

void enumerate_bits ( int k, int n, vector<bool> &a )
{
   if(k == n)
   {
      for(int i=0; i<n; i++)
         cout << " " << a[i];
      cout << endl;
   }
   else
   {
      a[k] = false;
      enumerate_bits(k+1,n,a);
      a[k] = true;
      enumerate_bits(k+1,n,a);
   }
}

