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;
}

全部评论

相关推荐

每晚夜里独自颤抖:要求太多的没必要理
点赞 评论 收藏
分享
缒梦&独舞:这家公司是这样的,去年给我实习offer了,不过也是面着玩儿的,他周六还要去做公益志愿活动
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务