Guest User

Untitled

a guest
Jul 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. void getPath(vector<int> path, vector<int>& f, vector<int>::iterator cur, vector<vector<int>>& result){
  8. if(cur>=f.end()){
  9. result.push_back(path);
  10. return;
  11. }
  12. if(path.empty()){
  13. getPath(path, f, next(cur), result);
  14. }
  15. else if(*cur!=path.back()){
  16. getPath(path, f, next(cur), result);
  17. }
  18. path.push_back(*cur);
  19. getPath(path, f, next(cur), result);
  20. }
  21. vector<vector<int>> getSubsets(vector<int>& f){
  22. vector<int> s;
  23. vector<vector<int>> result;
  24. getPath(s, f, f.begin(), result);
  25. return result;
  26. }
  27.  
  28. int main() {
  29. vector<int> f = {1, 1 ,2, 3, 4};
  30. sort(f.begin(), f.end());
  31. vector<vector<int>> allSubsets = getSubsets(f);
  32. for(auto list: allSubsets){
  33. for(auto x: list){
  34. cout<<x<<",";
  35. }
  36. cout<<endl;
  37. }
  38. return 0;
  39. }
Add Comment
Please, Sign In to add comment