代码拉取完成,页面将自动刷新
思路:
类似burst ballon 的dp 区间解法
代码:
import java.util.*;
class Solution {
int dp[][];
public int solve(int[] A) {
// Write your code here
dp=new int[A.length][A.length];
for(int i=0;i<dp.length;i++){
Arrays.fill(dp[i],-1);
}
return dfs(A,1,A.length-2);
}
public int dfs(int A[],int l,int r){
if(l>r)return 0;
if(dp[l][r]!=-1)return dp[l][r];
int res=Integer.MIN_VALUE;
for(int i=l;i<=r;i++){
res=Math.max(res,get(A,l-1)+get(A,r+1)+A[i]+dfs(A,l,i-1)+dfs(A,i+1,r));
}
dp[l][r]=res;
return res;
}
public int get(int A[],int i){
if(i<0||i>=A.length)return 0;
return A[i];
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。