8. (What we want)
(Build up the array bottom to top.)
w1
v1
w2
v2
wi
vi
wn-1
vn-1
wn
vn
… …
9. A[i] stores the best value for the first i items.
(What we want)
(Build up the array bottom to top.)
w1
v1
w2
v2
wi
vi
wn-1
vn-1
wn
vn
… …
10. A[i] stores the best value for the first i items.
A[i] = max(A(i-1), A[i-1] + vi)
(What we want)
(Build up the array bottom to top.)
w1
v1
w2
v2
wi
vi
wn-1
vn-1
wn
vn
… …
11. A[i] stores the best value for the first i items.
(What we want)
(Build up the array bottom to top.)
w1
v1
w2
v2
wi
vi
wn-1
vn-1
wn
vn
… …
12. (What we want)
(Build up the array bottom to top.)
w1
v1
w2
v2
wi
vi
wn-1
vn-1
wn
vn
… …
13. A[i,j] stores the best value for the first i items.
(What we want)
(Build up the array bottom to top.)
w1
v1
w2
v2
wi
vi
wn-1
vn-1
wn
vn
… …
that fits in a knapsack of size j.
14. A[i,j] stores the best value for the first i items.
A[i,j] = max(A(i-1,j), A[i-1,j-wi] + vi)
(What we want)
(Build up the array bottom to top.)
w1
v1
w2
v2
wi
vi
wn-1
vn-1
wn
vn
… …
that fits in a knapsack of size j.
46. (What we want)
(Build up the array bottom to top.)
c[i,j] stores the edit distance between
x[1…i] and y[1…j].
47. (What we want)
(Build up the array bottom to top.)
c[i,j] stores the edit distance between
x[1…i] and y[1…j].
c[i,j] = min(c[i-1,j] + w1, c[i,j-1] + w2, c[i-1,j-1] + w3)
48. (What we want)
(Build up the array bottom to top.)
c[i,j] stores the edit distance between
x[1…i] and y[1…j].