It's like Best Time to Buy and Sell Stock II. Go to solve that problem and see the explanation here firstly.
In this problem, we can define three array named sell
, buy
, and rest
, everyday we can sell, buy, or rest, it's the DP problem as well.
Think it over.