'commit'
This commit is contained in:
26
GESP/Mkx/20250322T2.cpp
Normal file
26
GESP/Mkx/20250322T2.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 11000;
|
||||
// 是path的集合,每个path表示一种上台阶的方法
|
||||
string paths[N]; // 字符串数组,每一个元素都是字符串
|
||||
int pl;
|
||||
|
||||
void dfs(int u, string path) { // 有 n 阶要爬
|
||||
if (u == 0) {
|
||||
paths[pl++] = path; // 爬完了
|
||||
return;
|
||||
}
|
||||
dfs(u - 1, path + "1"); // 我上了一阶,还有 n-1 阶
|
||||
dfs(u - 2, path + "2"); // 我上了 2 阶,还有 n-1 阶
|
||||
}
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
dfs(n, "");
|
||||
cout << pl << endl;
|
||||
|
||||
for (int i = 0; i < pl; i++)
|
||||
cout << paths[i] << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user