walkccc / CLRS

📚 Solutions to Introduction to Algorithms Third Edition
https://walkccc.me/CLRS
MIT License
4.62k stars 1.25k forks source link

16.2-2 #477

Open ustcjsj opened 1 year ago

ustcjsj commented 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)

ustcjsj commented 1 year ago

the initialization part you have to initialize it from 0

walkccc commented 1 year ago

Hi @ustcjsj,

Can you create a PR for this. Thanks!