mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-02 11:15:19 +08:00
* 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
33 lines
665 B
C++
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;
|
|
}
|