Alannix @ 2024-03-05 19:33:32
#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 JOKER_chu @ 2024-03-05 19:50:56
#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 <= n; i++)
{
if (st[i] == 0)
{
a[step] = i;
st[i] = 1;
dfs(step + 1, m);
st[i] = 0;
}
}
return;
}
int main() {
cin >> n >> m;
dfs(1, m);
return 0;
}
@Blanchard
by Alannix @ 2024-03-07 10:07:27
@chuxm 佬是不是没把改的码粘上去quq
by JOKER_chu @ 2024-03-07 12:50:30
@Blanchard
就是这个啊
by Alannix @ 2024-03-10 09:50:44
@chuxm 蒟蒻没看清不好意思佬Orz