Dynamic Programming

Compare to Greedy and Divide_and_conquer

Greedy.
Build up a solution incrementally, myopically optimizing some local criterion.

Divide-and-conquer.
Break up a problem into sub-problem into sub-problems, solve each sub-problem independently, and combine solutions to sub-problems to form solution to original problem.

Dynamic programming.
Break up a problem into a series of overlapping sub-problems, and build up solutions to larger and larger sub-problem.

Dynamic programming hallmark

Optimal substructure
An optimal solution to a problem(instance) contains optimal solutions to subproblems.

Overlapping subproblems
A recursive solution contains a “small” number of distinct subproblems repeated many times.

Example:Weighted Interval Scheduling

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

Memoization是常常和动态规划搭配使用的解决重复计算问题的放法,其原理是自底向上计算值,并储存起来,需要用到的时候直接取存储的值,而不是像递归那样重新计算。

在这里插入图片描述

在这里插入图片描述
下面就是我说的自底向上的例子:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值