2 条题解

  • 1
    @ 2024-10-22 21:40:06
    #include <iostream>
    using namespace std;
    const int N = 15;
    bool st[N];
    int a[N],n;
    void dfs(int u){
        if(u == n){
            for(int i = 0 ; i < n ; i++){
                cout << a[i]<< ' ';
            }
            cout << '\n';
        }
        for(int i = 1 ; i <= n ; i++){
            if(!st[i]){
                a[u] = i;
                st[i] = 1;
                dfs(u + 1);
                st[i] = 0;
            }
        }
    }
    int main(){
        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
        cin >> n;
        dfs(0);
        return 0;
    }
    

    信息

    ID
    552
    时间
    1000ms
    内存
    128MiB
    难度
    5
    标签
    (无)
    递交数
    165
    已通过
    66
    上传者