Introduction To Algorithms15.3(unfinished)

本文深入探讨动态规划的两大核心要素:最优子结构与重叠子问题。解析如何通过剪切粘贴技巧验证子问题解决方案的最优性,并介绍动态规划如何将指数级递归算法优化至多项式时间复杂度。

Dynamic Programing(动态规划)

Elements of dynamic programming

The two ingredients that an optimization problem must have in order for dynamic programming to apply:

  1. optimal substructure
  2. 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

  1. A solution to the problem consists of making a choice, which making the choice leaves subproblems to be solved.
  2. Then you are given a choice leading to optimal solution.
  3. According the choice you make, subproblems and the resulting space of subproblems emerge.
  4. 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

  1. how many subproblems an optimal solution to the original problem uses, and
  2. 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值