Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int n = 3;
- vector<int> p = { 1,2,3 };
- string str;
- vector<int> moves;
- vector<int> curent;
- vector<vector<int>> permutations;
- void lex(int pos)
- {
- bool isAdded = false;
- for (int i = 0; i < n; i++)
- {
- bool isFound = false;
- for (const auto& it : moves)
- if (it == p[i])
- {
- isFound = true;
- break;
- }
- if (!isFound)
- {
- isAdded = true;
- moves.push_back(p[i]);
- lex(pos + 1);
- }
- }
- if (!isAdded)
- {
- permutations.push_back(moves);
- }
- if (!moves.empty())
- moves.pop_back();
- }
- void main()
- {
- lex(0);
- for (auto& it : permutations)
- {
- for (auto& jt : it)
- {
- cout << jt;
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement