标签:
1.首先来看看维基百科怎么定义的动态规划
引自wiki:Dynamic programming
In mathematics, management science, economics, computer science, and bioinformatics, dynamic programming (also known as dynamic optimization) is a method for solving a complex problem by breaking it down into a collection of simpler subproblems, solving
each of those subproblems just once, and storing their solutions - ideally, using a memory-based data structure. The next time the same subproblem occurs, instead of recomputing its solution, one simply looks up the previously computed solution, thereby saving
computation time at the expense of a (hopefully) modest expenditure in storage space. (Each of the subproblem solutions is indexed in some way, typically based on the values of its input parameters, so as to facilitate its lookup.) The technique of storing
solutions to subproblems instead of recomputing them is called "memoization".
Dynamic programming algorithms are often used for optimization. A dynamic programming algorithm will examine the previously solved subproblems and will combine their solutions to give the best solution for the
given problem. In comparison, a greedy algorithm treats the solution as some sequence of steps and picks the locally optimal choice at each step. Using a greedy algorithm does not guarantee an optimal solution, because picking locally optimal choices may result
in a bad global solution, but it is often faster to calculate. Fortunately, some greedy algorithms (such as Kruskal‘s or Prim‘s for minimum spanning trees) are proven to lead to the optimal solution.
For example, in the coin change problem of finding the minimum number of coins of given denominations needed to make a given amount, a dynamic programming algorithm would find an optimal solution for each amount by first finding an optimal solution for each
smaller amount and then using these solutions to construct an optimal solution for the larger amount. In contrast, a greedy algorithm might treat the solution as a sequence of coins, starting from the given amount and at each step subtracting the largest possible
coin denomination that is less than the current remaining amount. If the coin denominations are 1,4,5,15,20 and the given amount is 23, this greedy algorithm gives a non-optimal solution of 20+1+1+1, while the optimal solution is 15+4+4.
In addition to finding optimal solutions to some problem, dynamic programming can also be used for counting the number of solutions, for example counting the number of ways a certain amount of change can be made from a given collection of coins, or counting
the number of optimal solutions to the coin change problem described above.
Sometimes, applying memoization to the naive recursive algorithm (namely the one obtained by a direct translation of the problem into recursive form) already results in a dynamic programming algorithm with asymptotically optimal time complexity, but for optimization
problems in general the optimal algorithm might require more sophisticated algorithms. Some of these may be recursive (and hence can be memoized) but parametrized differently from the naive algorithm. For other problems the optimal algorithm may not even be
a memoized recursive algorithm in any reasonably natural sense. An example of such a problem is the Egg Dropping puzzle described below.
在文章的 第二段和第三段加黄背景的文字,第二段说明了与贪婪算法的不同并通过第三段的举例,同一个问题贪婪算法可能会得不到全局最优解,23=20+1+1+1,而动态规划是23=15+4+4得到全局最优解
还有在wiki
Greedy algorithm 中有张图片:来说明贪婪算法有可能得不到全局最优解,但是幸运的是
Kruskal‘s or Prim‘s for minimum spanning trees 达到了全局最优解
2.然后我看 清华大学研究生公共课教材---数学系列---最优化理论与算法(第二版)陈宝林 编著
在最后第16章,以最短路线问题例介绍了动态规划,并定义了动态规划中的几个常用的术语。
1.阶段
2.状态
3.决策
4.策略
5.状态转移方程
6.指标函数
7.最优策略和最优轨线
在第二节提出了 R.Bellman的最优性原理:一个最优策略的子策略总是最优的
3. 算法导论中的动态规划
提到在动态规划方法的最优化问题中的两个要素:最优子结构和重叠子问题。
详细请看 算法导论P202
4.然后看知乎大神的解答:
dynamic programming is a method for solving a complex problem bybreaking it down into a collection of simpler subproblems.动态规划是通过拆分问题,定义问题状态和状态之间的关系,使得问题能够以递推(或者说分治)的方式去解决。
给定一个数列,长度为N,要解决这个问题,我们首先要定义这个问题和这个问题的子问题。
求这个数列的最长上升(递增)子数列(LIS)的长度.
以
1 7 2 8 3 4
为例。
这个数列的最长递增子数列是 1 2 3 4,长度为4;
次长的长度为3, 包括 1 7 8; 1 2 3 等.
给定一个数列,长度为N,显然,这个新问题与原问题等价。
设为:以数列中第k项结尾的最长递增子序列的长度.
求 中的最大值.
给定一个数列,长度为N,这个新定义与原问题的等价性也不难证明,请读者体会一下。
设为:
在前i项中的,长度为k的最长递增子序列中,最后一位的最小值. .
若在前i项中,不存在长度为k的最长递增子序列,则为正无穷.
求最大的x,使得不为正无穷。
设为:以数列中第k项结尾的最长递增子序列的长度.设A为题中数列,状态转移方程为:
(根据状态定义导出边界情况)用文字解释一下是:
设为:在数列前i项中,长度为k的递增子序列中,最后一位的最小值设A为题中数列,状态转移方程为:
若则(边界情况需要分类讨论较多,在此不列出,需要根据状态定义导出边界情况。)
否则:
分治在求解每个子问题的时候,都要进行一遍计算这就像说多加辣椒的菜就叫川菜,多加酱油的菜就叫鲁菜一样,是存在误解的。
动态规划则存储了子问题的结果,查表时间为常数
标签:
原文地址:http://blog.csdn.net/u010566813/article/details/51224640