mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-29 00:54:26 +00:00
Re-translate the Japanese version (#1871)
* Retranslate Japanese docs with GPT-5.4 * Retranslate Japanese code with GPT-5.4
This commit is contained in:
@@ -7,23 +7,23 @@
|
||||
package chapter_dynamic_programming;
|
||||
|
||||
public class climbing_stairs_dp {
|
||||
/* 階段登り:動的プログラミング */
|
||||
/* 階段登り:動的計画法 */
|
||||
public static int climbingStairsDP(int n) {
|
||||
if (n == 1 || n == 2)
|
||||
return n;
|
||||
// DPテーブルを初期化し、部分問題の解を格納するために使用
|
||||
// 部分問題の解を保存するために dp テーブルを初期化
|
||||
int[] dp = new int[n + 1];
|
||||
// 初期状態:最小の部分問題の解を事前設定
|
||||
// 初期状態:最小部分問題の解をあらかじめ設定
|
||||
dp[1] = 1;
|
||||
dp[2] = 2;
|
||||
// 状態遷移:小さな問題から大きな部分問題を段階的に解く
|
||||
// 状態遷移:小さい部分問題から大きい部分問題へ順に解く
|
||||
for (int i = 3; i <= n; i++) {
|
||||
dp[i] = dp[i - 1] + dp[i - 2];
|
||||
}
|
||||
return dp[n];
|
||||
}
|
||||
|
||||
/* 階段登り:空間最適化動的プログラミング */
|
||||
/* 階段登り:空間最適化した動的計画法 */
|
||||
public static int climbingStairsDPComp(int n) {
|
||||
if (n == 1 || n == 2)
|
||||
return n;
|
||||
@@ -40,9 +40,9 @@ public class climbing_stairs_dp {
|
||||
int n = 9;
|
||||
|
||||
int res = climbingStairsDP(n);
|
||||
System.out.println(String.format("%d段の階段を登る解は%d通りです", n, res));
|
||||
System.out.println(String.format("%d 段の階段の登り方は全部で %d 通り", n, res));
|
||||
|
||||
res = climbingStairsDPComp(n);
|
||||
System.out.println(String.format("%d段の階段を登る解は%d通りです", n, res));
|
||||
System.out.println(String.format("%d 段の階段の登り方は全部で %d 通り", n, res));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user