Files
python/TangDou/LuoGuBook/P1157_dfs_vector.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

26 lines
593 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}