public int maxProfit(int[] prices) {
if(prices.length <= 1)
return 0;
int[] c = new int[prices.length];
int[] s = new int[prices.length];
c[0] = 0;
c[1] = 0;
s[1] = prices[1]  prices[0];
for(int i = 2; i < prices.length; i++){
c[i] = Math.max(s[i1], c[i1]);
// If current state is cool down,
s[i] = prices[i]  prices[i1] + Math.max(c[i2], s[i1]);
// If current state is sold, assume it was sold at [i1]
}
return Math.max(c[prices.length1], s[prices.length1]);
}
Fast & Clean DP Solution in Java


s[i] = prices[i]  prices[i1] + Math.max(c[i2], s[i1]);
May I understand it this way? c[i2] equals buy[i1], means buy on i  1 and sell it on i; s[i1] is selling on i1, but actually you should not sell it so early, you should sell it on today (i) so you add profit difference (i to i 1) back? But it seems not right..