C++ 代码
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 30;
int a[N];
int n, m;
bool st[N];
void dfs(int u)
{
if (u == m)
{
for (int i = 0; i < m; i ++ )
printf("%d ", a[i]);
printf("\n");
return ;
}
for (int i = 1; i <= n; i ++ )
if (!st[i] && a[u - 1] < i)
{
a[u] = i;
st[i] = true;
dfs(u + 1);
st[i] = false;
}
}
int main()
{
cin >> n >> m;
dfs(0);
return 0;
}