这题是一道搜索题
只要DFS加上回溯就OK了
#include<bits/stdc++.h>
using namespace std;
int n,m,a[25],b[25];
void dg(int l,int r)
{
if(l==m)
{
for(int i=1;i<=m;i++)
{
cout<<setw(3)<<a[i];
}
cout<<"\n";
return;
}
if(r<=n)
{
a[l+1]=r;
dg(l+1,r+1);
dg(l,r+1);
}
return;
}
int main ()
{
cin>>n>>m;
dg(0,1);
}