Created
June 25, 2017 13:07
-
-
Save opethe1st/d66037f73f8db13b2dc46cba38611143 to your computer and use it in GitHub Desktop.
Enumerate all possible subsets of a set.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
void enumerate(vector<int> arr){ | |
for(int current_set = 0; current_set < (1<<(arr.size()-1)); current_set++){ | |
for(int j=0; j<arr.size(); j++){ // j is the position in arr. | |
if (current_set & (1<<j)){ // if the bit is set in this set, then arr[j] is in the set | |
cout<<arr[j]<<','; | |
} | |
} | |
cout<<endl; | |
} | |
} | |
int main(){ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment