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.

29 lines
719 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
int n;
int sum;
/**
* @param level
* N
* : 5 8
* : 15 987
*
*/
void dfs(int level) {
//如果可以走到第n个台阶表示可以成功登顶算是一个解决方案
if (level == n) sum++;
//2种分枝
for (int i = 1; i <= 2; i++)
if (level + i <= n) dfs(level + i);
}
int main() {
cin >> n;
dfs(0);
printf("一共 %d 种方法。\n", sum);
return 0;
}