This commit is contained in:
krahets
2023-11-11 23:03:42 +08:00
parent 0105644232
commit d5a58e0deb
6 changed files with 103 additions and 99 deletions

View File

@ -32,7 +32,7 @@ comments: true
for choice in choices:
# 剪枝:不允许越过第 n 阶
if state + choice > n:
break
continue
# 尝试:做出选择,更新状态
backtrack(choices, state + choice, n, res)
# 回退
@ -58,7 +58,7 @@ comments: true
for (auto &choice : choices) {
// 剪枝:不允许越过第 n 阶
if (state + choice > n)
break;
continue;
// 尝试:做出选择,更新状态
backtrack(choices, state + choice, n, res);
// 回退
@ -87,7 +87,7 @@ comments: true
for (Integer choice : choices) {
// 剪枝:不允许越过第 n 阶
if (state + choice > n)
break;
continue;
// 尝试:做出选择,更新状态
backtrack(choices, state + choice, n, res);
// 回退
@ -117,7 +117,7 @@ comments: true
foreach (int choice in choices) {
// 剪枝:不允许越过第 n 阶
if (state + choice > n)
break;
continue;
// 尝试:做出选择,更新状态
Backtrack(choices, state + choice, n, res);
// 回退
@ -147,7 +147,7 @@ comments: true
for _, choice := range choices {
// 剪枝:不允许越过第 n 阶
if state+choice > n {
break
continue
}
// 尝试:做出选择,更新状态
backtrack(choices, state+choice, n, res)
@ -182,7 +182,7 @@ comments: true
for choice in choices {
// 剪枝:不允许越过第 n 阶
if state + choice > n {
break
continue
}
backtrack(choices: choices, state: state + choice, n: n, res: &res)
}
@ -209,7 +209,7 @@ comments: true
// 遍历所有选择
for (const choice of choices) {
// 剪枝:不允许越过第 n 阶
if (state + choice > n) break;
if (state + choice > n) continue;
// 尝试:做出选择,更新状态
backtrack(choices, state + choice, n, res);
// 回退
@ -242,7 +242,7 @@ comments: true
// 遍历所有选择
for (const choice of choices) {
// 剪枝:不允许越过第 n 阶
if (state + choice > n) break;
if (state + choice > n) continue;
// 尝试:做出选择,更新状态
backtrack(choices, state + choice, n, res);
// 回退
@ -272,7 +272,7 @@ comments: true
// 遍历所有选择
for (int choice in choices) {
// 剪枝:不允许越过第 n 阶
if (state + choice > n) break;
if (state + choice > n) continue;
// 尝试:做出选择,更新状态
backtrack(choices, state + choice, n, res);
// 回退
@ -300,7 +300,7 @@ comments: true
// 遍历所有选择
for &choice in choices {
// 剪枝:不允许越过第 n 阶
if state + choice > n { break; }
if state + choice > n { continue; }
// 尝试:做出选择,更新状态
backtrack(choices, state + choice, n, res);
// 回退
@ -331,7 +331,7 @@ comments: true
int choice = choices[i];
// 剪枝:不允许越过第 n 阶
if (state + choice > n)
break;
continue;
// 尝试:做出选择,更新状态
backtrack(choices, state + choice, n, res, len);
// 回退
@ -365,7 +365,7 @@ comments: true
for (choices) |choice| {
// 剪枝:不允许越过第 n 阶
if (state + choice > n) {
break;
continue;
}
// 尝试:做出选择,更新状态
backtrack(choices, state + choice, n, res);