State transition equation
The formula that computes a state's solution from smaller states that are already solved.
Example
In stair climbing, dp[i] = dp[i β 1] + dp[i β 2]: with dp[3] = 3 and dp[4] = 5, dp[5] = 8.
Test yourself: State transition equation
Dynamic programming
The formula dp[i] = dp[i β 1] + dp[i β 2] is the state ___ equation.
It goes from states i β 1 and i β 2 to state i: from dp[4] = 5 and dp[3] = 3 to dp[5] = 8.
Solving with DP
dp[i, j] = min(dp[i β 1, j], dp[i, j β 1]) + ___.
You add the cost of the cell you reach: if above is 4, left is 2 and the cell costs 5, it gives 7.
0-1 knapsack
dp[i, c] = ___(dp[i β 1, c], dp[i β 1, c β wgt[i β 1]] + val[i β 1]).
We want the highest value: dp[3, 4] = max(16, 5 + 15) = 20.
0/3
βΆ Play