diff --git a/docs/chapter_dynamic_programming/unbounded_knapsack_problem.md b/docs/chapter_dynamic_programming/unbounded_knapsack_problem.md index 74403af4c..6b62900f1 100644 --- a/docs/chapter_dynamic_programming/unbounded_knapsack_problem.md +++ b/docs/chapter_dynamic_programming/unbounded_knapsack_problem.md @@ -1531,8 +1531,12 @@ $$ int n = coinsSize; int MAX = amt + 1; // 初始化 dp 表 - int *dp = calloc(amt + 1, sizeof(int)); + int *dp = malloc((amt + 1) * sizeof(int)); + for (int j = 1; j <= amt; j++) { + dp[j] = MAX; + } dp[0] = 0; + // 状态转移 for (int i = 1; i <= n; i++) { for (int a = 1; a <= amt; a++) { diff --git a/zh-Hant/docs/chapter_dynamic_programming/unbounded_knapsack_problem.md b/zh-Hant/docs/chapter_dynamic_programming/unbounded_knapsack_problem.md index fe200cdbc..371f46368 100644 --- a/zh-Hant/docs/chapter_dynamic_programming/unbounded_knapsack_problem.md +++ b/zh-Hant/docs/chapter_dynamic_programming/unbounded_knapsack_problem.md @@ -1531,8 +1531,12 @@ $$ int n = coinsSize; int MAX = amt + 1; // 初始化 dp 表 - int *dp = calloc(amt + 1, sizeof(int)); + int *dp = malloc((amt + 1) * sizeof(int)); + for (int j = 1; j <= amt; j++) { + dp[j] = MAX; + } dp[0] = 0; + // 狀態轉移 for (int i = 1; i <= n; i++) { for (int a = 1; a <= amt; a++) {