新学DFS,将以前暴力过的题重过,结果连模板题都过不了(QWQ
# include<bits/stdc++.h>
using namespace std;
int n, a[10], book[10];
void dfs(int step){
if(step == n){
for(int i = 1; i <= n; i++)
cout << setw(5) << a[i];
cout << endl;
return;
}
for(int i = step + 1; i <= n; i++){
if(book[i]){
a[i] = i;
book[i] = 1;
dfs(step + 1);
book[i] = 0;
}
}
}
int main(){
cin >> n;
dfs(0);
return 0;
}