Update stock notes
This commit is contained in:
parent
331178cb2c
commit
f7adb3ab9f
@ -16,3 +16,18 @@
|
|||||||
- `dp[0][0] = -prices[0]`
|
- `dp[0][0] = -prices[0]`
|
||||||
- `dp[0][1] = 0`
|
- `dp[0][1] = 0`
|
||||||
- 遍历顺序:从前往后
|
- 遍历顺序:从前往后
|
||||||
|
|
||||||
|
## [123.买卖股票的最佳时机III](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-iii/)
|
||||||
|
|
||||||
|
- `dp[i][j][k]` 是第 `i` 笔交易中,第 `j` 天,是否持有股票时的总资产
|
||||||
|
- 递推公式:
|
||||||
|
- `dp[0][i][0] = max(dp[0][i - 1][0], -prices[i])`
|
||||||
|
- `dp[0][i][1] = max(dp[0][i - 1][1], dp[0][i][0] + prices[i])`
|
||||||
|
- `dp[1][i][0] = max(dp[1][i - 1][0], dp[0][i - 1][1] - prices[i])`
|
||||||
|
- `dp[1][i][1] = max(dp[1][i - 1][1], dp[0][i - 1][0] + prices[i])`
|
||||||
|
- 初始化:
|
||||||
|
- `dp[i][0][0] = -prices[0]`
|
||||||
|
- `dp[i][0][1] = 0`
|
||||||
|
- 遍历顺序:
|
||||||
|
- 先遍历 `i`
|
||||||
|
- 再遍历 `j` 和 `k`
|
||||||
|
Loading…
Reference in New Issue
Block a user