> For the complete documentation index, see [llms.txt](https://851958789.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://851958789.gitbook.io/notes/0309_best_time_to_buy_and_sell_stock_with_cooldown/slt.md).

# Solution 1 DP + state machine

由题目可知，股票买卖有3个状态， 定义 dp\[i]\[0],表示第i天持有股票 定义 dp\[i]\[1],表示第i天处于冷冻期，且不持有股票 (刚卖) 定义 dp\[i]\[2]，表示第i天不处于冷冻期，且不持有股票

状态机见：

<https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/solution/czhuang-tai-ji-dong-tai-gui-hua-by-zhang-fcid/>

```
dp[i][0] = max(dp[i-1][0], dp[i-1][2] - prices[i])
dp[i][1] = dp[i-1][0] + prices[i]
dp[i][2] = max(dp[i-1][1], dp[i-1][2])
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://851958789.gitbook.io/notes/0309_best_time_to_buy_and_sell_stock_with_cooldown/slt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
