Advertisement
Sanlover

Untitled

Mar 4th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int n = 3;
  8. vector<int> p = { 1,2,3 };
  9. string str;
  10.  
  11. vector<int> moves;
  12. vector<int> curent;
  13. vector<vector<int>> permutations;
  14.  
  15. void lex(int pos)
  16. {
  17. bool isAdded = false;
  18. for (int i = 0; i < n; i++)
  19. {
  20. bool isFound = false;
  21. for (const auto& it : moves)
  22. if (it == p[i])
  23. {
  24. isFound = true;
  25. break;
  26. }
  27. if (!isFound)
  28. {
  29. isAdded = true;
  30. moves.push_back(p[i]);
  31. lex(pos + 1);
  32. }
  33. }
  34. if (!isAdded)
  35. {
  36. permutations.push_back(moves);
  37. }
  38. if (!moves.empty())
  39. moves.pop_back();
  40. }
  41.  
  42. void main()
  43. {
  44. lex(0);
  45. for (auto& it : permutations)
  46. {
  47. for (auto& jt : it)
  48. {
  49. cout << jt;
  50. }
  51. cout << endl;
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement