



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of dynamic programming, a method for solving optimization problems using recurrences. The steps involved in dynamic programming, including obtaining a formulation for the problem state, setting up the recurrence equations, and solving them iteratively. The document also includes an example of the 0/1 knapsack problem and its iterative solution.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




y
f[i][y] 0 1 2 3 4 5 6 7 8
i
y
f[i][y] 0 1 2 3 4 5 6 7 8
i
0 0 3 3 3 3 3 3 3
y
f[i][y] 0 1 2 3 4 5 6 7 8
i
0 0 3 3 3 3 3 3 3 0 0 3 3 3 3 9 9 12
f(i,y) = max{f(i+1,y), f(i+1,y-wi) + pi}, y >= wi
y
f[i][y] 0 1 2 3 4 5 6 7 8
i
0 0 3 3 3 3 3 3 3 0 0 3 3 3 3 9 9 12 0 0 3 3 3 10 10 13 13
f(i,y) = max{f(i+1,y), f(i+1,y-wi) + pi}, y >= wi
y
f[i][y] 0 1 2 3 4 5 6 7 8
i
0 0 3 3 3 3 3 3 3 0 0 3 3 3 3 9 9 12 0 0 3 3 3 10 10 13 13 0 0 3 8 8 11 11 13 18
f(i,y) = max{f(i+1,y), f(i+1,y-wi) + pi}, y >= wi
y
f[i][y] 0 1 2 3 4 5 6 7 8
i
0 0 3 3 3 3 3 3 3 0 0 3 3 3 3 9 9 12 0 0 3 3 3 10 10 13 13 0 0 3 8 8 11 11 13 18 18
f(i,y) = max{f(i+1,y), f(i+1,y-wi) + pi}, y >= wi
// initialize f[n][] int yMax = Math.min(w[n] - 1, c); for (int y = 0; y <= yMax; y++) f[n][y] = 0; for (int y = w[n]; y <= c; y++) f[n][y] = p[n];
// compute f[i][y], 1 < i < n for (int i = n - 1; i > 1; i--) { yMax = Math.min(w[i] - 1, c); for (int y = 0; y <= yMax; y++) f[i][y] = f[i + 1][y]; for (int y = w[i]; y <= c; y++) f[i][y] = Math.max(f[i + 1][y], f[i + 1][y - w[i]] + p[i]); }
// compute f[1][c] f[1][c] = f[2][c]; if (c >= w[1]) f[1][c] = Math.max(f[1][c], f[2][c-w[1]] + p[1]); }
k = 1
n C(i,j) = A(i,k) * B(k,j)