#include <iostream>
#include <vector>
#include <iomanip>
void print( const std::vector<bool>& seq )
{
for( bool b : seq ) std::cout << std::setw(5) << b << "; " ;
std::cout << '\n' ;
}
void generate( std::vector<bool>& seq, std::vector<bool>::iterator from )
{
if( from == seq.end() ) print(seq) ;
else
{
*from = false ;
generate( seq, from+1 ) ;
*from = true ;
generate( seq, from+1 ) ;
}
}
void generate( std::size_t n )
{
std::vector<bool> seq(n) ;
generate( seq, seq.begin() ) ;
}
int main()
{
std::cout << std::boolalpha ;
generate(5) ; // 2^5 sequences
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8aW9tYW5pcD4KCnZvaWQgcHJpbnQoIGNvbnN0IHN0ZDo6dmVjdG9yPGJvb2w+JiBzZXEgKQp7CiAgICBmb3IoIGJvb2wgYiA6IHNlcSApIHN0ZDo6Y291dCA8PCBzdGQ6OnNldHcoNSkgPDwgYiA8PCAiOyAiIDsKICAgIHN0ZDo6Y291dCA8PCAnXG4nIDsKfQoKdm9pZCBnZW5lcmF0ZSggc3RkOjp2ZWN0b3I8Ym9vbD4mIHNlcSwgc3RkOjp2ZWN0b3I8Ym9vbD46Oml0ZXJhdG9yIGZyb20gKQp7CiAgICBpZiggZnJvbSA9PSBzZXEuZW5kKCkgKSBwcmludChzZXEpIDsKICAgIGVsc2UKICAgIHsKICAgICAgICAqZnJvbSA9IGZhbHNlIDsKICAgICAgICBnZW5lcmF0ZSggc2VxLCBmcm9tKzEgKSA7CiAgICAgICAgKmZyb20gPSB0cnVlIDsKICAgICAgICBnZW5lcmF0ZSggc2VxLCBmcm9tKzEgKSA7CiAgICB9Cn0KCnZvaWQgZ2VuZXJhdGUoIHN0ZDo6c2l6ZV90IG4gKQp7CiAgIHN0ZDo6dmVjdG9yPGJvb2w+IHNlcShuKSA7CiAgIGdlbmVyYXRlKCBzZXEsIHNlcS5iZWdpbigpICkgOwp9CgppbnQgbWFpbigpCnsKICAgIHN0ZDo6Y291dCA8PCBzdGQ6OmJvb2xhbHBoYSA7CiAgICBnZW5lcmF0ZSg1KSA7IC8vIDJeNSBzZXF1ZW5jZXMKfQo=