码迷,mamicode.com
首页 > 其他好文 > 详细

Dynamic Programming

时间:2015-01-11 14:41:02      阅读:235      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!