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.

26 lines
593 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
int n, r;
//此答案不吸氧第8个测试点TLE吸氧后通过。
void dfs(int step, vector<int> path, int m) {
if (step == n + 1) return;
if (m == r) {
for (int i = 0; i < r; i++) printf("%3d", path[i]);
printf("\n");
return;
}
//下一个数字选择上
vector<int> p1 = path;
p1.push_back(step + 1);
dfs(step + 1, p1, m + 1);
//下一个数字放弃掉
dfs(step + 1, path, m);
}
int main() {
cin >> n >> r;
dfs(0, {}, 0);
return 0;
}