@
waytodelay #10 没关系,一般人都会将动态规划错误地同等于 bottom-up ,但是动态规划包含了 bottom-up 和 top-down ,而 top-down 相对来说更加容易实现,当你完成了 top-down 之后,你就会很容易得出 bottom-up 版本。
From Poe - Sage:
Dynamic programming can be implemented using a bottom-up approach or a top-down approach.
In the bottom-up approach, also known as the "tabulation" method, the solution to a problem is computed iteratively starting from the smallest subproblem and building up to the larger problem. This approach is typically implemented using a table or array to store intermediate results. The advantage of the bottom-up approach is that it often has better space complexity than the top-down approach, since it avoids the overhead of recursion.
In the top-down approach, also known as the "memoization" method, the solution to a problem is computed recursively, but with the added step of caching intermediate results so that they can be reused later. This approach can be more intuitive and easier to implement than the bottom-up approach, but it can suffer from the overhead of recursion and may not be as efficient in terms of space complexity.
Both approaches have their advantages and disadvantages depending on the problem at hand.