Dynamic Programing(动态规划)
Elements of dynamic programming
The two ingredients that an optimization problem must have in order for dynamic programming to apply:
- optimal substructure
- overlapping subproblems
1. Optimal substructure
What’s Optimal substructure?
Recall that a problem exhibits optimal substructure if an optimal solution to the problem contains within it optimal solutions to subproblems.(回想一下,如果问题的最优解包含子问题的最优解,则该问题具有最优子结构。)
Common pattern in discovering optimal substructure
- A solution to the problem consists of making a choice, which making the choice leaves subproblems to be solved.
- Then you are given a choice leading to optimal solution.
- According the choice you make, subproblems and the resulting space of subproblems emerge.
- You show that the solutions to the subproblems used within an optimal solution to the problem must themselves be optimal by using a “cut-and-paste” technique.
Rule to characterize the space of subproblems
Keep the space as simple as possible and then expand it as necessary.
Optimal substructure contains
- how many subproblems an optimal solution to the original problem uses, and
- how many choices we have in determining which subproblem(s) to use in an optimal solution.
Running time
n1 = number of subproblems
n2 = number of choices
running time = O(n1×n2n1\times n2n1×n2)
Independence - one property of subproblems
The solution to one subproblem does not affect the solution to another subproblem of the same problem.
Another interpretation : The resources used in one subproblems and others’ resources do not overlap.
2. Overlapping subproblems
When a recursive algorithm revisits the same problem repeatedly, we say that the optimization problem has overlapping subproblems.
Advantage
Our dynamic-programming solution takes an exponential-time recursive algorithm down to quadratic time.
Reconstructing an optimal solution
As a practical matter, we often store which choice we made in each subproblem in a table so that we do not have to reconstruct this information from the costs that we store,
Memorization
When the subproblem is first encountered as the recursive algorithm unfolds, its solution is computed and then stored in the table. Each subsequent time that we encounter this subproblem, we simply look up the value stored in the table and return it.
Without memoization, the natural recursive algorithm runs in exponential time, since solved subproblems are repeatedly solved.
本文深入探讨动态规划的两大核心要素:最优子结构与重叠子问题。解析如何通过剪切粘贴技巧验证子问题解决方案的最优性,并介绍动态规划如何将指数级递归算法优化至多项式时间复杂度。

1711

被折叠的 条评论
为什么被折叠?



