//
// main.cpp
// Bitmask
//
// Created by Himanshu on 18/07/22.
//
#include<iostream>
#include<cmath>
#include <bitset>
#include<vector>
#define N 3
using namespace std;
void findSubsets (int k, int ki[]) {
long subsetCount = (long int)pow(2,(double)N);
for (long i=0; i<subsetCount; i++) {
int pos = 0; //variable for current bit position (0th - N-1th)
long x = i; //integer to be used for bitmasking (0 <= x < 2^N)
bool flag = false;
bitset<N> subset;
while (x > 0) {
//Checking if the last bit from the right is set or not
if (x&1) {
//Checking if the current bit is the excluded (ki) bit or not
for (int j=0; j<k; j++) {
if (pos == ki[j]) {
flag = true;
}
}
if (flag) {
break;
} else {
//Adding current bit to the subset
subset.set(pos, 1);
}
} else {
//Setting the current bit as 0 if it's unset in x
subset.set(pos, 0);
}
//shifting 1 bit to right, to check the next bit
//and incresing position (pos) of the current bit by 1
x = x >> 1;
pos++;
}
if (!flag) {
cout<<subset<<endl;
}
}
}
int main() {
int k = 1;
int *ki = new int[k]();
ki[0] = 0;
cout<<"Subsets with 0th bit unset:"<<endl;
findSubsets(k, ki);
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBCaXRtYXNrCi8vCi8vICBDcmVhdGVkIGJ5IEhpbWFuc2h1IG9uIDE4LzA3LzIyLgovLwoKI2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGNtYXRoPgojaW5jbHVkZSA8Yml0c2V0PgojaW5jbHVkZTx2ZWN0b3I+CiNkZWZpbmUgTiAzCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIGZpbmRTdWJzZXRzIChpbnQgaywgaW50IGtpW10pIHsKICAgIAogICAgbG9uZyBzdWJzZXRDb3VudCA9IChsb25nIGludClwb3coMiwoZG91YmxlKU4pOwoKICAgIGZvciAobG9uZyBpPTA7IGk8c3Vic2V0Q291bnQ7IGkrKykgewogICAgICAgIAogICAgICAgIGludCBwb3MgPSAwOyAgLy92YXJpYWJsZSBmb3IgY3VycmVudCBiaXQgcG9zaXRpb24gKDB0aCAtIE4tMXRoKQogICAgICAgIAogICAgICAgIGxvbmcgeCA9IGk7IC8vaW50ZWdlciB0byBiZSB1c2VkIGZvciBiaXRtYXNraW5nICgwIDw9IHggPCAyXk4pCiAgICAgICAgCiAgICAgICAgYm9vbCBmbGFnID0gZmFsc2U7CiAgICAgICAgCiAgICAgICAgYml0c2V0PE4+IHN1YnNldDsKCiAgICAgICAgd2hpbGUgKHggPiAwKSB7CgogICAgICAgICAgICAvL0NoZWNraW5nIGlmIHRoZSBsYXN0IGJpdCBmcm9tIHRoZSByaWdodCBpcyBzZXQgb3Igbm90CiAgICAgICAgICAgIGlmICh4JjEpIHsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgLy9DaGVja2luZyBpZiB0aGUgY3VycmVudCBiaXQgaXMgdGhlIGV4Y2x1ZGVkIChraSkgYml0IG9yIG5vdAogICAgICAgICAgICAgICAgZm9yIChpbnQgaj0wOyBqPGs7IGorKykgewogICAgICAgICAgICAgICAgICAgIGlmIChwb3MgPT0ga2lbal0pIHsKICAgICAgICAgICAgICAgICAgICAgICAgZmxhZyA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBpZiAoZmxhZykgewogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAvL0FkZGluZyBjdXJyZW50IGJpdCB0byB0aGUgc3Vic2V0CiAgICAgICAgICAgICAgICAgICAgc3Vic2V0LnNldChwb3MsIDEpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgCiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAvL1NldHRpbmcgdGhlIGN1cnJlbnQgYml0IGFzIDAgaWYgaXQncyB1bnNldCBpbiB4CiAgICAgICAgICAgICAgICBzdWJzZXQuc2V0KHBvcywgMCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgCiAgICAgICAgICAgIC8vc2hpZnRpbmcgMSBiaXQgdG8gcmlnaHQsIHRvIGNoZWNrIHRoZSBuZXh0IGJpdAogICAgICAgICAgICAvL2FuZCBpbmNyZXNpbmcgcG9zaXRpb24gKHBvcykgb2YgdGhlIGN1cnJlbnQgYml0IGJ5IDEKICAgICAgICAgICAgeCA9IHggPj4gMTsKICAgICAgICAgICAgcG9zKys7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIGlmICghZmxhZykgewogICAgICAgICAgICBjb3V0PDxzdWJzZXQ8PGVuZGw7CiAgICAgICAgfQogICAgfQogICAgCn0KIAppbnQgbWFpbigpIHsKICAgIAogICAgaW50IGsgPSAxOwogICAgaW50ICpraSA9IG5ldyBpbnRba10oKTsKICAgIGtpWzBdID0gMDsKICAgICAgICAKICAgIGNvdXQ8PCJTdWJzZXRzIHdpdGggMHRoIGJpdCB1bnNldDoiPDxlbmRsOwogICAgZmluZFN1YnNldHMoaywga2kpOwogICAgCiAgICByZXR1cm4gMDsKfQ==