[LeetCode]312. Burst Balloons
来源:互联网 发布:淘宝培训班多少学费 编辑:程序博客网 时间:2024/06/09 15:33
思考:上周日做了爱奇艺的算法比赛,被通知无缘复赛,虽然没有为这个比赛准备什么,可心里觉得还是有些不爽!学习如逆水行舟,不进则退!再过段时间就是校园招聘了,该好好加强一下算法功底了!
这道题目和算法导论上面的“矩阵连乘”,“Floyd最短路算法“还有“石子合并问题(直线版)” 有相似之处!
题目链接
import java.util.Scanner;class Solution1 { public int maxCoins(int[] iNums) { int[] nums = new int[iNums.length + 2]; int n = 1; for (int x : iNums) { if (x > 0) { nums[n++] = x; } } nums[0] = nums[n++] = 1; int[][] dp = new int[n][n]; for (int k = 2; k < n; ++k) { for (int l = 0; l < n - k; ++l) { int r = l + k; for (int m = l + 1; m < r; ++m) { dp[l][r] = Math.max(dp[l][r], nums[l] * nums[m] * nums[r] + dp[l][m] + dp[m][r]); } } } return dp[0][n - 1]; }}public class Solution { private static Scanner scanner; public static void main(String[] args) { int num[] = new int[510]; scanner = new Scanner(System.in); int n = scanner.nextInt(); int read; int index = 0; for(int i = 0; i < n; i++) { read = scanner.nextInt(); num[index++] = read; } Solution1 solution = new Solution1(); int res = solution.maxCoins(num); System.out.println(res); }}
阅读全文
0 0
- leetcode 312. Burst Balloons
- [leetcode] 312. Burst Balloons
- LeetCode 312. Burst Balloons
- LeetCode 312. Burst Balloons
- leetcode.312. Burst Balloons
- 【leetcode】312. Burst Balloons
- LeetCode 312. Burst Balloons
- leetcode 312. Burst Balloons
- leetcode 312.Burst Balloons
- Leetcode-312. Burst Balloons
- 【Leetcode】312. Burst Balloons
- 【leetcode】312. Burst Balloons
- 【leetcode】312. Burst Balloons
- LeetCode 312. Burst Balloons
- 【Leetcode】312. Burst Balloons
- 【LeetCode】312. Burst Balloons
- 【LeetCode】312. Burst Balloons
- leetcode 312. Burst Balloons
- Docker基本命令
- 电脑中了比特币勒索病毒怎么清除?
- cocos2dx-lua基础内容之 菜单项的使用
- YTU3133--进阶递归之引爆炸弹(搜索)
- springboot 生产环境与开发环境配置
- [LeetCode]312. Burst Balloons
- GPIOPS中断成功,问题仍旧存在 ZEDBOARD,ZYNQ-7000
- SiteServer CMS的表结构说明
- 给Java初学者一些建议,勿错过!
- Phpcms v9 实现首页|列表页|内容页调用点击量的代码
- VC6.0 C++ 得到系统时间
- 短信验证
- 基于SSL中间证书的指纹识别技术
- js Date format