题目链接:点击这里
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const int MOD = 10000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int maxn = 1010;
int n, m;
void dfs(int idx, int now, int state) //state二进制数记录结果
{
if(now + n - idx < m) return; //把后面的数都选上也达不到m个
if(now==m)
{
for(int i = 0; i < n; ++i)
if(state >> i & 1) //state第i位是否为1
printf("%d ", i+1); //因为是1~n,所以这里i+1
printf("\n");
return;
}
//字典序较小的排在前面,所以,先选再不选
dfs(idx + 1, now + 1, state|1<<idx); //选idx,即state第idx位置成1
dfs(idx + 1, now, state); //不选idx
}
int main()
{
scanf("%d%d", &n, &m);
dfs(0, 0, 0);
return 0;
}