![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/097127c9592b64366f041eae6f613270.png)
#include<iostream>
using namespace std;
int n;
bool vis[16];
void dfs(int x){
if(x>n){
for(int i=1;i<=n;i++){
if(vis[i]){
cout<<i<<" ";
}
}
cout<<"\n";
return ;
}
vis[x]=1;
dfs(x+1);
vis[x]=0;
dfs(x+1);
}
int main(){
cin>>n;
dfs(1);
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b1de2d9e88413aebf5e99e611d51521a.png)
#include<iostream>
using namespace std;
int n;
bool vis[10];
int path[10];
void dfs(int x){
if(x>n){
for(int i=1;i<=n;i++){
cout<<path[i]<<" ";
}
cout<<"\n";
return ;
}
for(int i=1;i<=n;i++){
if(!vis[i]){
vis[i]=1;
path[i]=x;
dfs(x+1);
vis[i]=0;
path[i]=0;
}
}
}
int main(){
cin>>n;
dfs(1);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main(){
string s="bca";
do{
cout<<s<<endl;
}while(next_permutation(s.begin(),s.end()));
return 0;
}
bca
cab
cba
#include <bits/stdc++.h>
using namespace std;
int main(){
string s="bca";
sort(s.begin(),s.end());
do{
cout<<s<<endl;
}while(next_permutation(s.begin(),s.end()));
return 0;
}
abc
acb
bac
bca
cab
cba