首页 > 其他 > 详细

Dynamic Programming

时间:2015-01-11 14:39:19      阅读:284      评论:0      收藏:0      [点我收藏+]

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)

 

Dynamic Programming

原文:http://www.cnblogs.com/neweracoding/p/4216376.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!