using System;
using System.Collections.Generic;
class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 两次交易所能获得的最大收益
* @param prices int整型一维数组 股票每一天的价格
* @return int整型
*/
public int maxProfit (List<int> prices) {
int[] dp = new int[5];
dp[1] = -prices[0];
dp[3] = -prices[0];
for(int i = 1; i < prices.Count; i++){
for(int j = 1; j < 5; j++){
if(j % 2 == 0){//卖出去
dp[j] = Math.Max(dp[j], dp[j - 1] + prices[i]);
}
else{//买进来
dp[j] = Math.Max(dp[j], dp[j - 1] - prices[i]);
}
}
}
return dp[4];
}
}