Additional DP Optimizations and Techniques
Author: Andi Qu
Additional dynamic programming techniques and optimizations like Knuth's optimization.
Knuth's Optimization
Tutorials
Resources | ||||
---|---|---|---|---|
Jeffrey Xiao | ||||
GCP | ||||
GFG | Good explanation + Proof of correctness |
Knuth's optimization is a special case of Range DP. In general, it is used to solve DP problems with transitions of the form
Further, the cost function must satisfy the following conditions for all :
- (the quadrangle inequality)
Define be the index for which takes on its minimum value, or equivalently,
If more than one such index exists, then take the minimum (or the maximum, doesn't matter). Then, assuming conditions on the dp transition and the cost function to be satisfied, we can show that satisfies
The proof of correctness for this claim is in the resources above.
The structure of the code is identical to that of Range DP, with the exception of maintaining the array. To calculate and , it is only necessary to check values of between and . Because of the monotonicity of , the time complexity of the final algorithm can be shown to be .
Knuth's Optimization Problems
Status | Source | Problem Name | Difficulty | Tags | |
---|---|---|---|---|---|
CF | Easy | ||||
SPOJ | Normal | ||||
onlinejudge.org | Normal | ||||
onlinejudge.org | Hard |
Connected-Component DP
Resources | ||||
---|---|---|---|---|
CF | Miscellaneous techniques |
Connected-Component DP Problems
This section is not complete.
Make Permutations II a focus problem, move analysis to module.
Status | Source | Problem Name | Difficulty | Tags | |
---|---|---|---|---|---|
CSES | Easy | ||||
CF | Easy | ||||
CEOI | Normal | ||||
CF | Normal | ||||
JOI | Normal | ||||
CF | Normal |
Module Progress:
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!