Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #define SB(mask, k) (mask |= (1 << k))
- #define TB(mask, k) (mask ^= (1 << k))
- #define GB(mask, k) ((bool)(mask & (1 << k)))
- using namespace std;
- int n;
- void generarPermutaciones(int &usado, vector <int> &permutacion)
- {
- if(permutacion.size() == n)
- {
- for(int i=0; i<permutacion.size(); i++)
- cout << permutacion[i] << " ";
- cout << endl;
- return;
- }
- for(int i=1; i<=n; i++)
- {
- if(GB(usado, i) == false)
- {
- permutacion.push_back(i);
- TB(usado, i);
- generarPermutaciones(usado, permutacion);
- permutacion.pop_back();
- TB(usado, i);
- }
- }
- }
- int main()
- {
- cin >> n;
- int usado = 0;
- vector <int> permutacion;
- generarPermutaciones(usado, permutacion);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement