You are given the stock prices for a set of days . Each day, you can either buy one unit of stock, sell any number of stock units you have already bought, or do nothing. What is the maximum profit you can obtain by planning your trading strategy optimally?
Now the answer can be obtained through single pass but what if it has to be solved through Dynamic Programming. What will be the recurrence relation then for the problem?
I think for any day OPT(i)
can denote maximum profit earned so far, so one has to sell all remaining shares on the last day so
OPT(i) = max (
Sell all on this day bought from day j to day i + OPT(j-1),
OPT(i-1) + do nothing)?
Is this right?