Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- void getPath(vector<int> path, vector<int>& f, vector<int>::iterator cur, vector<vector<int>>& result){
- if(cur>=f.end()){
- result.push_back(path);
- return;
- }
- if(path.empty()){
- getPath(path, f, next(cur), result);
- }
- else if(*cur!=path.back()){
- getPath(path, f, next(cur), result);
- }
- path.push_back(*cur);
- getPath(path, f, next(cur), result);
- }
- vector<vector<int>> getSubsets(vector<int>& f){
- vector<int> s;
- vector<vector<int>> result;
- getPath(s, f, f.begin(), result);
- return result;
- }
- int main() {
- vector<int> f = {1, 1 ,2, 3, 4};
- sort(f.begin(), f.end());
- vector<vector<int>> allSubsets = getSubsets(f);
- for(auto list: allSubsets){
- for(auto x: list){
- cout<<x<<",";
- }
- cout<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment