#include<vector> #include<algorithm> using std::vector;
classSolution { public: intmaxProfit(int k, vector<int> &prices) { int i, j, n = prices.size(); int nr_state = 2 * k + 1; if (n == 1) { return0; } // dp[i][j] represents the maximum profit on the i-th day in the j-th state vector<vector<int> > dp(n, vector<int>(nr_state, 0)); dp[0][0] = 0; dp[0][1] = -prices[0]; for (j = 2; j < nr_state; j++) { dp[i][j] = -1e9; }