-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPower Set.cpp
More file actions
33 lines (29 loc) · 721 Bytes
/
Copy pathPower Set.cpp
File metadata and controls
33 lines (29 loc) · 721 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
#include<bits/stdc++.h>
using namespace std;
void powerSet(string, string, vector<string>&);
int main(){
int t, n;
string str, res;
cin >> t;
while(t--){
cin >> n >> str;
sort(&str[0], &str[0] + str.length());
vector<string> s;
powerSet(res, str, s);
sort(s.begin(), s.end());
for(auto it = s.begin(); it != s.end(); it++)
cout << *it << " ";
cout << endl;
}
return 0;
}
void powerSet(string res, string str, vector<string> &s){
if(!res.empty())
s.push_back(res);
while(str[0] != '\0'){
string temp = str;
temp.erase(0, 1);
powerSet(res + str[0], temp, s);
str = temp;
}
}