1 Dynamic Programming
The most widely example we use Dynamic Programming in our life is find the shortest/quickest path between two places.So what is the Dynamic Programming?
Dynamic programming refers to simplifying a complicated problem by breaking it down into simpler subproblems in a recursive manner. If subproblems can be nested recursively inside larger problems, so that dynamic programming methods are applicable,then there is a relation between the value of the larger problem and the values of the subproblems. In computer science, a problem that can be broken down recursively is said to have optimal substructure. 动态规划适用于最优化问题,即要做出一组选择以达到一个最优解。在做选择的同时,经常出现同样形式的子问题,关键技术是存储这些字问题每一个的解,以备重复出现。
There are two key attributes that a problem must have in order for dynamic programming to be applicable:optimal substructure(最优子结构) and overlapping subproblems(重叠子问题). If a problem can be solved by combining optimal solutions to non-overlapping subproblems, the strategy is called "divide and conquer". This is why mergesort and quicksort are not classified as dynamic programming problems.
(Note:why mergesort and quicksort are not classified as dynamic programming problems?
The key words here are "overlapping subproblems" and "optimal substructure". When you execute quicksort or mergesort, you are recursively breaking down your array into smaller pieces that do not overlap. You never operate over the same elements of the original array twice during any given level of the recursion.This means there is no opportunity to re-use previous calculations. On the other hand,many problems using dynamic programming involve performing the same calculations overlapping subsets, and have the useful characteristic that an optimal solution to a subproblem can be re-used when computing the optimal solution to a larger problem.)
Optimal Substructure
Optimal substructure means that the solution to a given optimization problem can be obtained by the combination of optimal solutions to its subproblems(如果问题的一个最优解中包含了子问题的最优解,则该问题具有最优子结构).Consequently, the first step towards devising a dynamic programming solution is to check whether the problem exhibits such optimal substructure. Such optimal substructures are usually described by means of recursion. For example, given a graph G=(V,E), the shortest path p from a vertex u to a vertex vexhibits optimal substructure: take any intermediate vertex w on this shortest path p. If p is truly the shortest path, then the path p1 from u to w and p2 from w to v are indeed the shortest paths between the corresponding vertices (by the simple cut-and-paste argument described in Introduction to Algorithms). Hence, one can easily formulate the solution for finding shortest paths in a recursive manner.
Overlapping subproblems