33 lines
570 B
C++
33 lines
570 B
C++
#include <iostream>
|
|
#include <vector>
|
|
using namespace std;
|
|
|
|
template <class T>
|
|
void dfs(vector<T>& _path, vector<bool>& _used, int n) {
|
|
if(_path.size() == n){
|
|
for(auto x : _path) cout << x << " ";
|
|
cout << endl;
|
|
return;
|
|
}
|
|
for(int i = 0; i < n; i++){
|
|
if(!_used[i]) {
|
|
_used[i] = true;
|
|
_path.push_back(i + 1);
|
|
dfs(_path, _used, n);
|
|
_path.pop_back();
|
|
_used[i] = false;
|
|
}
|
|
}
|
|
for(auto x : _path) cout << x << " ";
|
|
cout << endl;
|
|
}
|
|
|
|
int main(){
|
|
int n;
|
|
cin >> n;
|
|
vector<int> path;
|
|
vector<bool> used(n, false);
|
|
dfs(path, used, n);
|
|
return 0;
|
|
}
|