'commit'
This commit is contained in:
27
TangDou/LuoGuBook/P1157_dfs.cpp
Normal file
27
TangDou/LuoGuBook/P1157_dfs.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
int n, r;
|
||||
const int N = 110;
|
||||
int a[N];
|
||||
|
||||
void dfs(int step, int m) {
|
||||
if (step == n + 1) return;
|
||||
if (m == r) {
|
||||
for (int i = 1; i <= r; i++) printf("%3d", a[i]);
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
||||
//下一个数字选择上
|
||||
a[m + 1] = step + 1;
|
||||
dfs(step + 1, m + 1);
|
||||
|
||||
//下一个数字放弃掉
|
||||
dfs(step + 1, m);
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n >> r;
|
||||
dfs(0, 0);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user