递归实现组合型枚举
#include <iostream>
using namespace std;
int st[100];
int path[100];
int n, m;
void dfs(int u, int h){
if(u>m)
{
for(int i=1;i<=m;i++)
cout << path[i] << " ";
cout << endl;
return ;
}
for(int i=h;i<=n;i++)
{
if(!st[i] && u+n-h+1 >= m)
{
st[i] = 1;
path[u] = i;
dfs(u+1, i);
st[i] = 0;
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin >> n >> m;
dfs(1,1);
}