Dynamic Programming is an algorithmic paradigm that solves a given complex problem by breaking it into subproblems and stores the results of subproblems to avoid computing the same results again. Following are the two main properties of a problem that suggest that the given problem can be solved using Dynamic programming.
动态规划是一种典型的算法,它可以通过将一个给定的复杂问题分割为子问题,然后将子问题的结果进行存储以免再次计算相同的结果。当问题具有下面两个属性(特征)的时候,那么意思就是说这个问题可以用动态规划的思想来解决。
1) Overlapping Subproblems
2) Optimal Substructure
1) 重叠的子问题
2) 最优的子结构
1) Overlapping Subproblems:
Like Divide and Conquer, Dynamic Programming combines solutions to sub-problems. Dynamic Programming is mainly used when solutions of same subproblems are needed again and again. In dynamic programming, computed solutions to subproblems are stored in a table so that these don’t have to recomputed. So Dynamic Programming is not useful when there are no common (overlapping) subproblems because there is no point storing the solutions if they are not needed again. For example, Binary Search doesn’t have common subproblems. If we take example of following recursive program for Fibonacci Numbers, there are many subproblems which are solved again and again.