https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/

1) 코드
class Solution:
def maxProfit(self, prices: List[int]) -> int:
dp = {}
def dfs(i, buying):
if i >= len(prices):
return 0
if (i, buying) in dp:
return dp[(i, buying)]
maxProfit = 0
if buying:
sell = dfs(i+2, not buying) + prices[i]
cooldown = dfs(i+1, buying)
maxProfit = max(sell, cooldown)
else:
buy = dfs(i+1, not buying) - prices[i]
cooldown = dfs(i+1, buying)
maxProfit = max(buy, cooldown)
dp[(i, buying)] = maxProfit
return maxProfit
return dfs(0, False)
2) 설명