Best Time to Buy and Sell Stock 系列总结

Posted 珍妮的选择

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Best Time to Buy and Sell Stock 系列总结相关的知识,希望对你有一定的参考价值。


Best Time to Buy and Sell Stock 系列总结

强烈推荐: ​​Most consistent ways of dealing with the series of stock problems​​, 耐心仔细的全部看完, 收获不小.

Best Time to Buy and Sell Stock 系列有如下题目, 均可用动态规划进行求解, 有通用的递推公式:

通用的递推公式为:

Base cases:
T[-1][k][0] = 0, T[-1][k][1] = -Infinity
T[i][0][0] = 0, T[i][0][1] = -Infinity

Recurrence relations:
T[i][k][0] = max(T[i-1][k][0], T[i-1][k][1] + prices[i]) # sell
T[i][k][1] = max(T[i-1][k][1], T[i-1][k-1][0] - prices[i]) # buy

看 ​​Most consistent ways of dealing with the series of stock problems​​​ 或者 ​​123. Best Time to Buy and Sell Stock III***​​​ 获取关于 ​​T[i][k][*]​​ 的进一步解释.


以上是关于Best Time to Buy and Sell Stock 系列总结的主要内容,如果未能解决你的问题,请参考以下文章

最强解析面试题:best-time-to-buy-and-sell-stock

最强解析面试题:best-time-to-buy-and-sell-stock

121. Best Time to Buy and Sell Stock

122. Best Time to Buy and Sell Stock II

123. Best Time to Buy and Sell Stock III***

LeetCode 121. Best Time to Buy and Sell Stock