Skip to content

Optimal substructure

以"结构化思维"来看到substructure

"substructure"的"sub"提升了我们它对应的是"nest、contain关系"。

最优子结构其实就具备递归性质:全问题的最优解蕴含着子问题的最优解。

所以我们即可以自顶向下来运用递归关系也可以自底向上来运用递归关系。动态规划就是自底向上的。

labuladong 动态规划详解 # 二、凑零钱问题

其中给出了非常好的解释:

一、使用了高考刺成绩的例子

二、强调了 "子问题相互独立"

wikipedia Optimal substructure

In computer science, a problem is said to have optimal substructure if an optimal solution can be constructed from optimal solutions of its subproblems. This property is used to determine the usefulness of dynamic programming and greedy algorithms for a problem.[1]

NOTE:

1、optimal substructure其实也体现了递归关系

2、原问题 和 子问题

Typically, a greedy algorithm is used to solve a problem with optimal substructure if it can be proven by induction that this is optimal at each step.[1] Otherwise, provided the problem exhibits overlapping subproblems as well, dynamic programming is used. If there are no appropriate greedy algorithms and the problem fails to exhibit overlapping subproblems, often a lengthy but straightforward search of the solution space is the best alternative(使用搜索算法).

In the application of dynamic programming to mathematical optimization, Richard Bellman's Principle of Optimality is based on the idea that in order to solve a dynamic optimization problem from some starting period t to some ending period T, one implicitly has to solve subproblems starting from later dates s, where t<s<T. This is an example of optimal substructure. The Principle of Optimality is used to derive the Bellman equation, which shows how the value of the problem starting from t is related to the value of the problem starting from s.

Problems with optimal substructure

1、Longest common subsequence problem

2、Longest increasing subsequence

3、Longest palindromic substring

4、All-Pairs Shortest Path

5、Any problem that can be solved by dynamic programming.

Problems without optimal substructure

1、Longest path problem

2、Least-cost airline fare. (Using online flight search, we will frequently find that the cheapest flight from airport A to airport B involves a single connection through airport C, but the cheapest flight from airport A to airport C involves a connection through some other airport D.)