AcWing 93. 递归实现组合型枚举
原题链接
简单
作者:
uchar
,
2024-12-01 17:20:01
,
所有人可见
,
阅读 13
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int state[26];
bool used[26];
int n, m;
void dfs(int u)
{
if (u > m)
{
for (int i = 1; i <= m; i++)
printf("%d ", state[i]);
printf("\n");
return;
}
for (int i = 1; i <= n; i++)
if (!used[i] && i > state[u-1])
{
state[u] = i;
used[i] = true;
dfs(u + 1);
state[u] = 0;
used[i] = false;
}
}
int main()
{
scanf("%d%d", &n, &m);
dfs(1);
return 0;
}