general strategy
- Start with the recursive backtracking solution
- Optimize by using a memoization table (top-down[3] dynamic programming)
- Remove the need for recursion (bottom-up dynamic programming)
- Apply final tricks to reduce the time / memory complexity
When to use
- Input cannot sort
- Find minimum/maximum result
- Check the feasibility 找可行性
- Count all possible solutions 列出所有解 (Find count)
Principles
(1) 最优化原理:如果问题的最优解所包含的子问题的解也是最优的,就称该问题具有最优子结构,即满足最优化原理。
(2) 无后效性:即某阶段状态一旦确定,就不受这个状态以后决策的影响。也就是说,某状态以后的过程不会影响以前的状态,只与当前状态有关。
(3)有重叠子问题:即子问题之间是不独立的,一个子问题在下一阶段决策中可能被多次使用到。(该性质并不是动态规划适用的必要条件,但是如果没有这条性质,动态规划算法同其他算法相比就不具备优势
http://klausguan.com/2017/07/09/dynamic-programing/
ACM动态规划总结
Memorization + Search
e.g.
http://univasity.iteye.com/blog/1170216
Minmax
https://segmentfault.com/a/1190000013527949
Minimax is to deep search for the best value, assuming the opponent will always play the move with the worst value (worst for us, so best for them).
Classical Problems
Regex Matching
|
|
LIS (Linear)
Edit Distance (2D Array)
Backpack
guess money
|
|
best time to buy and sell stock
|
|
word break
|
|