straightforward but O(N^2)

class Solution { public: int maxProfit(vector<int>& prices) { int n = prices.size(); if(n==0) return 0; vector<int> dp(n,0); for(int i=1;i<n;i++) { dp[i] = dp[i-1]; for(int j=0;j<i;j++) { if(j==0 || j==1) dp[i] = max(dp[i],prices[i]-prices[j]); else { dp[i] = max(dp[i],prices[i]-prices[j] + dp[j-2]); } } } return dp[n-1]; } };Best Time to Buy and Sell Stock with Cooldown