Skip to content

Instantly share code, notes, and snippets.

@opethe1st
Created June 25, 2017 13:07
Show Gist options
  • Save opethe1st/d66037f73f8db13b2dc46cba38611143 to your computer and use it in GitHub Desktop.
Save opethe1st/d66037f73f8db13b2dc46cba38611143 to your computer and use it in GitHub Desktop.
Enumerate all possible subsets of a set.
#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