dfs-题解 | #全排列#
全排列
https://www.nowcoder.com/practice/5632c23d0d654aecbc9315d1720421c1
#include <iostream>
using namespace std;
const int N = 10;
int n;
char path[N];
bool st[N];
string s;
void dfs(int u){
if(u == n){
for(int i = 0; i < n; i ++) cout<<path[i];
cout<<endl;
return;
}
for(int i = 0; i < n; i ++){
if(!st[i]){
st[i] = true;
path[u] = s[i];
dfs(u + 1);
st[i] = false;
}
}
}
int main(){
cin>>s;
n = s.size();
dfs(0);
return 0;
}
查看3道真题和解析