标签:标记 bool max code image tar none cto inf
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int MAXN = 10;
bool isUsed[MAXN];
vector<int> ans;
int N;
void DFS(int index) {
if (index >= N) { //边界条件
for (int i = 0; i < ans.size(); ++i) {
printf("%d ",ans[i]);
}
printf("\n");
return ;
}
for (int i = 1; i <= N; ++i) {
if (isUsed[i]) {
continue;
}
ans.push_back(i);
isUsed[i] = true; //标记该节点被访问
DFS(index + 1);
ans.pop_back();
isUsed[i] = false;
}
}
int main() {
cin >> N;
DFS(0); //从第 0层开始
return 0;
}
标签:标记 bool max code image tar none cto inf
原文地址:https://www.cnblogs.com/snailzh/p/12483435.html