Files
hello-algo/ja/codes/cpp/chapter_dynamic_programming/climbing_stairs_dfs.cpp
T
Yudong Jin 7257641e0e Retranslate the complete Japanese online edition from Chinese (#2008)
* Retranslate the complete Japanese online edition from Chinese

* Fit Japanese homepage labels and localize heading permalinks

* Point Japanese contribution instructions to the Japanese preview

* Replace locale conditionals with multilingual UI tables
2026-10-30 02:12:26 +08:00

33 lines
665 B
C++

/**
* File: climbing_stairs_dfs.cpp
* Created Time: 2023-06-30
* Author: krahets ([email protected])
*/
#include "../utils/common.hpp"
/* 探索 */
int dfs(int i) {
// dp[1] と dp[2] は既知なので、その値を返す
if (i == 1 || i == 2)
return i;
// dp[i] = dp[i-1] + dp[i-2]
int count = dfs(i - 1) + dfs(i - 2);
return count;
}
/* 階段の上り方:探索 */
int climbingStairsDFS(int n) {
return dfs(n);
}
/* 実行用コード */
int main() {
int n = 9;
int res = climbingStairsDFS(n);
cout << "上る段数: " << n << " 段、上り方は全部で " << res << " 通り" << endl;
return 0;
}