mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-15 14:48:05 +08: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:
@@ -6,9 +6,9 @@
|
||||
|
||||
#include "../utils/common.hpp"
|
||||
|
||||
/* バックトラッキングアルゴリズム:順列 II */
|
||||
/* バックトラッキング:順列 II */
|
||||
void backtrack(vector<int> &state, const vector<int> &choices, vector<bool> &selected, vector<vector<int>> &res) {
|
||||
// 状態の長さが要素数と等しくなったら、解を記録
|
||||
// 状態の長さが要素数に等しければ、解を記録
|
||||
if (state.size() == choices.size()) {
|
||||
res.push_back(state);
|
||||
return;
|
||||
@@ -17,22 +17,22 @@ void backtrack(vector<int> &state, const vector<int> &choices, vector<bool> &sel
|
||||
unordered_set<int> duplicated;
|
||||
for (int i = 0; i < choices.size(); i++) {
|
||||
int choice = choices[i];
|
||||
// 剪定:要素の重複選択を許可せず、等しい要素の重複選択も許可しない
|
||||
// 枝刈り:要素の重複選択を許可せず、同値要素の重複選択も許可しない
|
||||
if (!selected[i] && duplicated.find(choice) == duplicated.end()) {
|
||||
// 試行:選択を行い、状態を更新
|
||||
duplicated.emplace(choice); // 選択された要素値を記録
|
||||
// 試行: 選択を行い、状態を更新
|
||||
duplicated.emplace(choice); // 選択済みの要素値を記録
|
||||
selected[i] = true;
|
||||
state.push_back(choice);
|
||||
// 次のラウンドの選択に進む
|
||||
// 次の選択へ進む
|
||||
backtrack(state, choices, selected, res);
|
||||
// 回退:選択を取り消し、前の状態に復元
|
||||
// バックトラック:選択を取り消し、前の状態に戻す
|
||||
selected[i] = false;
|
||||
state.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 順列 II */
|
||||
/* 全順列 II */
|
||||
vector<vector<int>> permutationsII(vector<int> nums) {
|
||||
vector<int> state;
|
||||
vector<bool> selected(nums.size(), false);
|
||||
@@ -41,7 +41,7 @@ vector<vector<int>> permutationsII(vector<int> nums) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/* ドライバーコード */
|
||||
/* Driver Code */
|
||||
int main() {
|
||||
vector<int> nums = {1, 1, 2};
|
||||
|
||||
@@ -53,4 +53,4 @@ int main() {
|
||||
printVectorMatrix(res);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user