AcWing 3429. 全排列
原题链接
简单
作者:
寻路
,
2022-07-05 11:25:02
,
所有人可见
,
阅读 170
DFS
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char path[10];
bool flag[26];
int len;
string str;
void dfs(int u) {
if (u == len) {
for (int i = 0; i < len; i ++ ) {
cout << path[i];
}
cout << endl;
} else {
for (int i = 0; i < len; i ++ ) {
if (!flag[str[i] - 'a']) {
flag[str[i] - 'a'] = true;
path[u] = str[i];
dfs(u + 1);
flag[str[i] - 'a'] = false;
}
}
}
}
int main() {
cin >> str;
len = str.size();
dfs(0);
return 0;
}