let memo = {}
var Fib = function(n){
if(n == 1 || n == 2){
return 1
}
if(n === 0){
return 0
}
if(!memo[n])
memo[n]=Fib(n-1)+Fib(n-2);
return memo[n];
}
var maxProfitIII = function(prices, times){
let DP = new Array(times + 1);
DP.fill(new Array(prices.length).fill(0))
console.log(DP)
for(let k = 1; k < times + 1; k++){
let tmpMax = -prices[0]
for(let i = 1; i < prices.length; i++){
DP[k][i] = Math.max(DP[k][i - 1], prices[i] + tmpMax)
tmpMax = Math.max(tmpMax, DP[k-1][i-1] - prices[i])
}
}
return DP[times][prices.length - 1]
}
console.log(maxProfitIII([2, 4, 1], 2))
console