maximizing profit for given stock data via DP

穿精又带淫゛_ 提交于 2019-12-07 07:39:28

I think you can solve like this:

dp[i][j] means the maximum profit you get while you are still holding j units of stock.

Then

dp[i][j] = max(dp[i-1][j-1] - cost, //buy one unit
               dp[i-1][j], // do nothing
               dp[i-1][j+1] + profit // sold one unit
               dp[i-1][j+2] + 2*profit //sold two units
               ...
               )

then find the maximum value of dp[N][j] (0<=j<=MAX)

The time is (number_of_days * total_stock_you_can_buy^2)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!