Files
hello-algo/ja/codes/csharp/chapter_dynamic_programming/climbing_stairs_dfs.cs
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

32 lines
757 B
C#

/**
* File: climbing_stairs_dfs.cs
* Created Time: 2023-06-30
* Author: hpstory ([email protected])
*/
namespace hello_algo.chapter_dynamic_programming;
public class climbing_stairs_dfs {
/* 探索 */
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);
}
[Test]
public void Test() {
int n = 9;
int res = ClimbingStairsDFS(n);
Console.WriteLine($"{n} 段の階段を上る方法は全部で {res} 通り");
}
}