1 Star 1 Fork 0

laodasbch/Leetcode-Complete-Guide

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
b708.txt 782 Bytes
一键复制 编辑 原始数据 按行查看 历史
JunB(66哥) 提交于 5年前 . Create b708.txt
思路:
类似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];
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/laodasbch/Leetcode-Complete-Guide.git
git@gitee.com:laodasbch/Leetcode-Complete-Guide.git
laodasbch
Leetcode-Complete-Guide
Leetcode-Complete-Guide
master

搜索帮助