标签:style turn max int bsp 买卖 ++ 股票 for
1 class Solution 2 { 3 public: 4 int maxProfit(vector<int>& prices, int fee) 5 { 6 int n = prices.size(); 7 vector<vector<int>> dp(n,vector<int>(2,0)); 8 9 dp[0][0] = 0; 10 dp[0][1] = -prices[0]; 11 for(int i = 1;i < n;i ++) 12 { 13 dp[i][0] = max(dp[i - 1][0],dp[i - 1][1] + prices[i] - fee);//没有持有 14 dp[i][1] = max(dp[i - 1][1],dp[i - 1][0] - prices[i]);//持有 15 } 16 return dp[n - 1][0]; 17 } 18 };
标签:style turn max int bsp 买卖 ++ 股票 for
原文地址:https://www.cnblogs.com/yuhong1103/p/12832042.html