很久没写博客了,越来越懒了,这次还是要分享LeetCode上一道动态规划的题目,和之前的Ballon Boom那个题(我记得是这个标题吧。。。)差不多,都是对一个数组的区间进行枚举的题,而且涉及到区间和子区间取值的问题,不过那个题和矩阵链乘法基本是一样的,

这个题的话相对来说更难一点,因为这个题需要对一个三维的dp数组进行维护,最后一个维度的考虑是比较难的。直接提供代码,思路以后有时间再补:

 class Solution {
public int removeBoxes(int[] boxes) {
if(boxes==null)return 0;
int len = boxes.length;
if(len<=1)return len*len;
int[][][]dp = new int[len][len][len];
for(int i = 0;i<len;i++)
for(int j = 0;j<=i;j++)
dp[i][i][j] = (1+j)*(1+j);
int res = 0;
for(int i = len-2;i>=0;i--) {
for(int j = i+1;j<len;j++) {
for(int k = 0;k<=i;k++) {
res = (1+k)*(1+k)+dp[i+1][j][0];
for(int m = i+1;m<=j;m++)
if(boxes[i]==boxes[m])res = Math.max(res,dp[i+1][m-1][0]+dp[m][j][k+1]);
dp[i][j][k] = res;
}
}
}
return dp[0][len-1][0];
}
}

动态规划——Remove Boxes的更多相关文章

  1. [LeetCode] Remove Boxes 移除盒子

    Given several boxes with different colors represented by different positive numbers. You may experie ...

  2. [Swift]LeetCode546. 移除盒子 | Remove Boxes

    Given several boxes with different colors represented by different positive numbers. You may experie ...

  3. 546. Remove Boxes

    Given several boxes with different colors represented by different positive numbers. You may experie ...

  4. 546 Remove Boxes 移除盒子

    给定一些不同颜色的盒子,以不同的正整数表示.消去连续相同颜色的盒子,直到全部消除完毕为止.每一次消去可以得到k * k分(k为消去盒子的个数, k  >= 1).计算可以得到的最大得分.注意:盒 ...

  5. 第十周 Leetcode 546. Remove Boxes (HARD) 记忆化搜索

    Leetcode546 给定一个整数序列,每次删除其中连续相等的子序列,得分为序列长度的平方 求最高得分. dp方程如下: memo[l][r][k] = max(memo[l][r][k], dfs ...

  6. Leetcode 546. Remove Boxes

    题目链接: https://leetcode.com/problems/remove-boxes/description/ 问题描述 若干个有序排列的box和它们的颜色,每次可以移除若干个连续的颜色相 ...

  7. leetcode动态规划题目总结

    Hello everyone, I am a Chinese noob programmer. I have practiced questions on leetcode.com for 2 yea ...

  8. Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 贪心/二分

    C. GukiZ hates Boxes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  9. Codeforces821C Okabe and Boxes 2017-06-28 15:24 35人阅读 评论(0) 收藏

    C. Okabe and Boxes time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. H5_0004:JS设置循环debugger的方法

    在HTML页面加上如下代码,则PC打开控制台后,就会循环debugger,防止调试代码. <script>eval(function (p, a, c, k, e, r) { e = fu ...

  2. 2019全国大学生信息安全竞赛部分Web writeup

    JustSoso 0x01 审查元素发现了提示,伪协议拿源码 /index.php?file=php://filter/read=convert.base64-encode/resource=inde ...

  3. SQL 耗时优化

    Ø  简介 在平常的开发中,我们经常会编写各种各样的 SQL 语句,比如:SQL 查询.存储过程.或者视图查询等.当我们编写的 SQL 语句比较复杂,或者表的数据量比较大,导致查询超时!这时,就要去分 ...

  4. js ajax方法模板

    ajax方法: $.ajax({ type: "POST", url: "WebService.asmx/sp_sj_yisheng_gexinhuaAdd", ...

  5. Thrax-构建基于语法的语言模型工具

    安装 http://www.openfst.org/twiki/bin/view/GRM/ThraxQuickTour http://cslu.ogi.edu/~sproatr/Courses/Tex ...

  6. JAVA进阶19

    1.冒泡排序 package cn.zh.abstrac; import java.util.Arrays; //冒泡排序 public class Demo019 { public static v ...

  7. word20170107当地交通 Local transportation有用的词和句子

    有用的词: transportation: 交通 airport express: 机场快线 shuttle bus: 班车 taxi/cab: 出租车 meter: 打表 limousine:专车. ...

  8. golang包管理工具glide安装

    1:下载安装glide go get github.com/Masterminds/glide glide的源码以及exe文件在第一个gopath目录,如果不知道哪个是第一个gopath,echo一下 ...

  9. Virtual Machine

    之前说到可以使用Assembly language来实现程序编写,把程序通过一个Assembler就可以得到计算机可以操作的二进制文件. 但是Assembly language依旧不适于编程,但怎么将 ...

  10. 备考2019年6月份PMP考试-分享一些(备考)考试心得

    I'm iron man,纪念离去的钢铁侠(复联4) 话说任何一个写程序的人都不可能干一辈子(有些人例外),大部分都是要转行的. 技术转管理是一条路,技术转创业是一条路,技术干销售是一条路,技术转售前 ...