842. 排列数字
作者:互联网
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n;
vector<int> path; //记录走的路径
bool st[N];
void dfs(int u) {
//如果到达了终点
if (u == n + 1) {
for (int i = 0; i < n; i++)
printf("%d ", path[i]);
printf("\n");
return;
}
for (int i = 1; i <= n; i++)
if (!st[i]) {
path.push_back(i);
st[i] = true;
dfs(u + 1);
st[i] = false;
path.pop_back();
}
}
int main() {
//读入优化
ios::sync_with_stdio(false);
cin >> n;
//开始
dfs(1);
return 0;
}
标签:排列,return,842,int,dfs,传送门,printf,path,数字 来源: https://www.cnblogs.com/littlehb/p/15305236.html