动态规划(1)总述

动态规划是一种解决最优化问题的算法,适用于具有最优子结构和重叠子问题的问题。它通过分解问题并存储子问题的解来避免重复计算。与分治算法不同,动态规划处理的是子问题的重叠。动态规划的应用包括最短路径、最大连续子串等,与贪心算法的主要区别在于贪心算法不保证总能得到全局最优解。动态规划的关键步骤包括描述最优子结构、递归定义最优解的值、自底向上计算最优解以及构造最优解。
摘要由CSDN通过智能技术生成

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 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值