活动地址:CSDN21天学习挑战赛
class Solution {
public int maxCoins(int[] nums) {
int length = nums.length;
int[] temp = new int[length+2];
for(int i = 1;i<=length;i++){
temp[i]=nums[i-1];
}
temp[0]=temp[length+1] = 1;
int[][] dp = new int[length+2][length+2];
for(int i = length-1;i>=0;i--){
for(int j = i+2;j<=length+1;j++){
for(int k = i+1;k<j;k++){
int sum = temp[i]*temp[k]*temp[j]+dp[i][k]+dp[k][j];
dp[i][j]=Math.max(sum,dp[i][j]);
}
}
}
return dp[0][length+1];
}
}