蒟蒻求求大佬67分qwq

B3623 枚举排列(递归实现排列型枚举)

Alannix @ 2024-03-05 19:33:42

#include<bits/stdc++.h>
using namespace std;
int a[101];
int st[101] = { 0 };
int n, m;
void dfs(int step, int m)
{
    if (step>m)
    {
        for (int i = 1; i <= m; i++)
        {
            cout << a[i] << " ";
        }
        cout << endl;
        return;
    }
    for (int i = 1; i <= m; i++)
    {
        if (st[i] == 0)
        {
            a[step] = i;
            st[i] = 1;
            dfs(step + 1, n);
            st[i] = 0;
        }
    }
    return;
}
int main() {
    cin >> n >> m;
    dfs(1, m);
    return 0;
}

by thehanged @ 2024-03-11 18:29:31

枚举n名学生啊

for (int i = 1; i <= n; i++)

by dengshunyang @ 2024-10-22 12:52:54

dfs(step+1,n)的n改成m


|