- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpowerSet.cpp
More file actions
Latest commit
34 lines (30 loc) · 602 Bytes
/
Copy pathpowerSet.cpp
File metadata and controls
34 lines (30 loc) · 602 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<bits/stdc++.h>
usingnamespacestd;
// power set - all subsequences
// a, ab, abc, b, bc, c, abc
// str = abc
// ind = 012
// i - 210
// -------
// 0 - 000 - ""
// 1 - 001 - a
// 2 - 010 - b
// 3 - 011 - ab
// 4 - 100 - c
// 5 - 101 - ac
// 6 - 110 - bc
// 7 - 111 - abc
intmain() {
string str = "abc";
int n = str.size();
string bit;
for(int i = 0 ; i < (1 << n) ; i++) {
bit = "";
for(int j = 0 ; j < n ; j++) {
if(i & (1 << j)) // if bit is on
bit += str[j];
}
cout << bit << endl;
}
return0;
}