mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-13 18:00:18 +08:00
Bug fixes and improvements (#1380)
* preorder, inorder, postorder -> pre-order, in-order, post-order * Bug fixes * Bug fixes * Update what_is_dsa.md * Sync zh and zh-hant versions * Sync zh and zh-hant versions. * Update performance_evaluation.md and time_complexity.md * Add @khoaxuantu to the landing page. * Sync zh and zh-hant versions * Add @ khoaxuantu to the landing page of zh-hant and en versions.
This commit is contained in:
@@ -31,7 +31,7 @@ function coinChangeDP(coins, amt) {
|
||||
return dp[n][amt] !== MAX ? dp[n][amt] : -1;
|
||||
}
|
||||
|
||||
/* 零錢兌換:狀態壓縮後的動態規劃 */
|
||||
/* 零錢兌換:空間最佳化後的動態規劃 */
|
||||
function coinChangeDPComp(coins, amt) {
|
||||
const n = coins.length;
|
||||
const MAX = amt + 1;
|
||||
@@ -61,6 +61,6 @@ const amt = 4;
|
||||
let res = coinChangeDP(coins, amt);
|
||||
console.log(`湊到目標金額所需的最少硬幣數量為 ${res}`);
|
||||
|
||||
// 狀態壓縮後的動態規劃
|
||||
// 空間最佳化後的動態規劃
|
||||
res = coinChangeDPComp(coins, amt);
|
||||
console.log(`湊到目標金額所需的最少硬幣數量為 ${res}`);
|
||||
|
||||
@@ -30,7 +30,7 @@ function coinChangeIIDP(coins, amt) {
|
||||
return dp[n][amt];
|
||||
}
|
||||
|
||||
/* 零錢兌換 II:狀態壓縮後的動態規劃 */
|
||||
/* 零錢兌換 II:空間最佳化後的動態規劃 */
|
||||
function coinChangeIIDPComp(coins, amt) {
|
||||
const n = coins.length;
|
||||
// 初始化 dp 表
|
||||
@@ -59,6 +59,6 @@ const amt = 5;
|
||||
let res = coinChangeIIDP(coins, amt);
|
||||
console.log(`湊出目標金額的硬幣組合數量為 ${res}`);
|
||||
|
||||
// 狀態壓縮後的動態規劃
|
||||
// 空間最佳化後的動態規劃
|
||||
res = coinChangeIIDPComp(coins, amt);
|
||||
console.log(`湊出目標金額的硬幣組合數量為 ${res}`);
|
||||
|
||||
@@ -82,7 +82,7 @@ function editDistanceDP(s, t) {
|
||||
return dp[n][m];
|
||||
}
|
||||
|
||||
/* 編輯距離:狀態壓縮後的動態規劃 */
|
||||
/* 編輯距離:空間最佳化後的動態規劃 */
|
||||
function editDistanceDPComp(s, t) {
|
||||
const n = s.length,
|
||||
m = t.length;
|
||||
@@ -130,6 +130,6 @@ console.log(`將 ${s} 更改為 ${t} 最少需要編輯 ${res} 步`);
|
||||
res = editDistanceDP(s, t);
|
||||
console.log(`將 ${s} 更改為 ${t} 最少需要編輯 ${res} 步`);
|
||||
|
||||
// 狀態壓縮後的動態規劃
|
||||
// 空間最佳化後的動態規劃
|
||||
res = editDistanceDPComp(s, t);
|
||||
console.log(`將 ${s} 更改為 ${t} 最少需要編輯 ${res} 步`);
|
||||
|
||||
@@ -69,7 +69,7 @@ function knapsackDP(wgt, val, cap) {
|
||||
return dp[n][cap];
|
||||
}
|
||||
|
||||
/* 0-1 背包:狀態壓縮後的動態規劃 */
|
||||
/* 0-1 背包:空間最佳化後的動態規劃 */
|
||||
function knapsackDPComp(wgt, val, cap) {
|
||||
const n = wgt.length;
|
||||
// 初始化 dp 表
|
||||
@@ -108,6 +108,6 @@ console.log(`不超過背包容量的最大物品價值為 ${res}`);
|
||||
res = knapsackDP(wgt, val, cap);
|
||||
console.log(`不超過背包容量的最大物品價值為 ${res}`);
|
||||
|
||||
// 狀態壓縮後的動態規劃
|
||||
// 空間最佳化後的動態規劃
|
||||
res = knapsackDPComp(wgt, val, cap);
|
||||
console.log(`不超過背包容量的最大物品價值為 ${res}`);
|
||||
|
||||
@@ -22,7 +22,7 @@ function minCostClimbingStairsDP(cost) {
|
||||
return dp[n];
|
||||
}
|
||||
|
||||
/* 爬樓梯最小代價:狀態壓縮後的動態規劃 */
|
||||
/* 爬樓梯最小代價:空間最佳化後的動態規劃 */
|
||||
function minCostClimbingStairsDPComp(cost) {
|
||||
const n = cost.length - 1;
|
||||
if (n === 1 || n === 2) {
|
||||
|
||||
@@ -69,7 +69,7 @@ function minPathSumDP(grid) {
|
||||
return dp[n - 1][m - 1];
|
||||
}
|
||||
|
||||
/* 最小路徑和:狀態壓縮後的動態規劃 */
|
||||
/* 最小路徑和:空間最佳化後的動態規劃 */
|
||||
function minPathSumDPComp(grid) {
|
||||
const n = grid.length,
|
||||
m = grid[0].length;
|
||||
@@ -116,6 +116,6 @@ console.log(`從左上角到右下角的最小路徑和為 ${res}`);
|
||||
res = minPathSumDP(grid);
|
||||
console.log(`從左上角到右下角的最小路徑和為 ${res}`);
|
||||
|
||||
// 狀態壓縮後的動態規劃
|
||||
// 空間最佳化後的動態規劃
|
||||
res = minPathSumDPComp(grid);
|
||||
console.log(`從左上角到右下角的最小路徑和為 ${res}`);
|
||||
|
||||
@@ -29,7 +29,7 @@ function unboundedKnapsackDP(wgt, val, cap) {
|
||||
return dp[n][cap];
|
||||
}
|
||||
|
||||
/* 完全背包:狀態壓縮後的動態規劃 */
|
||||
/* 完全背包:空間最佳化後的動態規劃 */
|
||||
function unboundedKnapsackDPComp(wgt, val, cap) {
|
||||
const n = wgt.length;
|
||||
// 初始化 dp 表
|
||||
@@ -58,6 +58,6 @@ const cap = 4;
|
||||
let res = unboundedKnapsackDP(wgt, val, cap);
|
||||
console.log(`不超過背包容量的最大物品價值為 ${res}`);
|
||||
|
||||
// 狀態壓縮後的動態規劃
|
||||
// 空間最佳化後的動態規劃
|
||||
res = unboundedKnapsackDPComp(wgt, val, cap);
|
||||
console.log(`不超過背包容量的最大物品價值為 ${res}`);
|
||||
|
||||
Reference in New Issue
Block a user