Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 4 3 2 1 5
- 4 3 5 1 2
- 2 3 4 1 5
- 2 3 5 1 4
- 5 3 2 1 4
- 5 3 4 1 2
- int perm[3] = {2, 4, 5};
- const int N = sizeof(perm) / sizeof(int);
- std::map<int,int> fixed; // note: zero-indexed
- fixed[1] = 3;
- fixed[3] = 1;
- do {
- for (int i=0, j=0; i<5; i++)
- if (fixed.find(i) != fixed.end())
- std::cout << " " << fixed[i];
- else
- std::cout << " " << perm[j++];
- std::cout << std::endl;
- } while (std::next_permutation(perm, perm + N));
- 2 3 4 1 5
- 2 3 5 1 4
- 4 3 2 1 5
- 4 3 5 1 2
- 5 3 2 1 4
- 5 3 4 1 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement