Introduction to Dynamic Programming

Introduction to Dynamic Programming
复制标题

DOI:
10.2307/1907500
复制
发表时间:
2022
期刊:
SSRN Electronic Journal
影响因子:
--
通讯作者:
Manel Baucells;Sasa Zorc
Manel Baucells;Sasa Zorc
中科院分区:
其他
文献类型:
--
作者:
Manel Baucells;Sasa Zorc

文献摘要

被引文献

相似文献

fib(5)已经被调用和重新计算了3次。为了加速我们的简单解决方案,我们可以通过计算fib()来使用DP,每个值直到n=10,并将其存储起来以备将来使用。实现这一点的一种方法是稍微修改原始的递归函数,以检查表,看看我们是否已经计算出了特定的Fibonacci数。如果有,我们就使用它,否则我们计算然后存储它。这是自顶向下的方法(也称为记忆),因为从整体问题开始,向下递归,直到我们到达最小的子问题(基本情况)。
Already, fib(5) is being called and recomputed 3 different times. To speed up our naive solution, we can employ DP by computing fib() for each value up to n=10 and storing it for future use. One way we can implement this is to slightly modify our original recursive function to check a table to see if we’ve already computed that specific Fibonacci number. If we have, we use it, otherwise we compute and then store it. This is the top-down approach(also called memoization) because start from the overall problem and recurse down until we reach the smallest subproblems (the base cases).