标签:
DP = Recursion + Memoization, A Smart Brute-force Algorithm
Divide the original problem into similar subproblems.
Hard desgin part: what are the subproblems. In fibonacci case, f(1), f(2), f(3) ... f(n-1) are the subproblems.
For DP problem, the running time = # of subproblems * time per subproblem (don‘t count memoized recursions)
Shortest Path Problem:
Design it in a navie recursive way, => improve by memoize the shortestPath(V1, V2).
However, this is a wrong algorith. It may cause infinite loop. (Infinite on graph with cycles)
So the lessen here is that subproblem dependency should be acyclic, otherwise we have infinite algorithm.
Techniques to turn a cyclic graph to an acyclic graph.(Create multiple copies, everytime along the edge, move to the next layer, it‘s like we are adding another dimension of number of edges in the path)
标签:
原文地址:http://www.cnblogs.com/neweracoding/p/4216376.html