You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
553 B

#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int a[N];
int n, k;
vector<int> path;
void dfs(int step, int m) {
if (m == k) {
for (int i = 0; i < path.size(); i++) cout << path[i] << " ";
cout << endl;
return;
}
if (step == n + 1) return;
//选择了当前数字
path.push_back(a[step]);
dfs(step + 1, m + 1);
path.pop_back();
//放弃当前数字
dfs(step + 1, m);
}
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++)a[i] = i;
dfs(1, 0);
return 0;
}