Open ustcjsj opened 1 year ago
0-1-KNAPSACK(n, W) Initialize an (n + 1) by (W + 1) table K for i = 0 to n K[i, 0] = 0 for j = 0 to W K[0, j] = 0 for i = 1 to n for j = 1 to W if j < i.weight K[i, j] = K[i - 1, j] else K[i, j] = max(K[i - 1, j], K[i - 1, j - i.weight] + i.value)
the initialization part you have to initialize it from 0
Hi @ustcjsj,
Can you create a PR for this. Thanks!
0-1-KNAPSACK(n, W) Initialize an (n + 1) by (W + 1) table K for i = 0 to n K[i, 0] = 0 for j = 0 to W K[0, j] = 0 for i = 1 to n for j = 1 to W if j < i.weight K[i, j] = K[i - 1, j] else K[i, j] = max(K[i - 1, j], K[i - 1, j - i.weight] + i.value)