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][*] 的进一步解释.

发布了227 篇原创文章 · 获赞 6 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Eric_1993/article/details/103883065