mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-03 19:52:01 +08:00
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
This commit is contained in:
@@ -11,26 +11,26 @@ import java.util.*;
|
||||
public class climbing_stairs_backtrack {
|
||||
/* バックトラッキング */
|
||||
public static void backtrack(List<Integer> choices, int state, int n, List<Integer> res) {
|
||||
// 第 n 段に到達したら、方法数を 1 増やす
|
||||
// n 段目に到達したら、方法の数を 1 増やす
|
||||
if (state == n)
|
||||
res.set(0, res.get(0) + 1);
|
||||
// すべての選択肢を走査
|
||||
// すべての選択肢を走査する
|
||||
for (Integer choice : choices) {
|
||||
// 枝刈り: 第 n 段を超えないようにする
|
||||
// 枝刈り:n 段目を越えてはならない
|
||||
if (state + choice > n)
|
||||
continue;
|
||||
// 試行: 選択を行い、状態を更新
|
||||
// 試行:選択を行い、状態を更新する
|
||||
backtrack(choices, state + choice, n, res);
|
||||
// バックトラック
|
||||
// 復元
|
||||
}
|
||||
}
|
||||
|
||||
/* 階段登り:バックトラッキング */
|
||||
/* 階段の上り方:バックトラッキング */
|
||||
public static int climbingStairsBacktrack(int n) {
|
||||
List<Integer> choices = Arrays.asList(1, 2); // 1 段または 2 段上ることを選べる
|
||||
int state = 0; // 第 0 段から上り始める
|
||||
List<Integer> choices = Arrays.asList(1, 2); // 1 段または 2 段上ることを選択できる
|
||||
int state = 0; // 0 段目から上り始める
|
||||
List<Integer> res = new ArrayList<>();
|
||||
res.add(0); // res[0] を使って方法数を記録する
|
||||
res.add(0); // res[0] に方法の数を記録する
|
||||
backtrack(choices, state, n, res);
|
||||
return res.get(0);
|
||||
}
|
||||
@@ -39,6 +39,6 @@ public class climbing_stairs_backtrack {
|
||||
int n = 9;
|
||||
|
||||
int res = climbingStairsBacktrack(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