leetcode 312 : Burst Balloons
来源:互联网 发布:淘宝售后培训ppt 编辑:程序博客网 时间:2024/05/17 08:48
1、原题如下:
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get nums[left] * nums[i] * nums[right] coins. Here left and right are adjacent indices of i. After the burst, the left and right then becomes adjacent.
Find the maximum coins you can collect by bursting the balloons wisely.
Note:
(1) You may imagine nums[-1] = nums[n] = 1. They are not real therefore you can not burst them.
(2) 0 ≤ n ≤ 500, 0 ≤ nums[i] ≤ 100Example:
Given [3, 1, 5, 8]
Return 167
nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []
coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167
2、解题如下:
class Solution {public: int maxCoins(vector<int>& nums) { int nums_new[nums.size()+2]; int check_zero=1; for(auto i: nums) if(i>0) nums_new[check_zero++]=i; nums_new[0]=nums_new[check_zero++]=1; int dp[check_zero][check_zero]={}; for(int j=2;j<check_zero;j++){ for(int left=0;left<check_zero-j;left++){ int right=left+j; for(int k=left+1;k<right;k++){ dp[left][right]=max(dp[left][right],nums_new[left]*nums_new[k]*nums_new[right]+dp[left][k]+dp[k][right]); } } } return dp[0][check_zero-1]; }};
1 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 - Hard
- LeetCode 312 Burst Balloons 题解
- LeetCode 312 Burst Balloons (区间dp)
- Leetcode 312 - Burst Balloons(区间dp)
- leetcode Burst Balloons
- Burst Balloons | LeetCode
- leetcode之Burst Balloons
- [LeetCode]Burst Balloons
- LeetCode Burst Balloons
- leetcode 312. Burst Balloons
- 相似性度量总结
- 1005.继续(3n+1)猜想
- JUnit简单安装使用步骤总结
- 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest F. Gourmet and Banquet(贪心+二分)
- java设计模式(三)—单例模式
- leetcode 312 : Burst Balloons
- Android之px、dp、sp之间相互转换
- 【数据结构实验】哈夫曼编/译码
- Android下的驱动开发框架
- 宏定义中的"#"和"##"符号
- Openstack在Centos上安装--(二)Mysql和RabbitMQ的安装与配置
- 1006.换个格式输出整数
- 为什么要进行URL编码
- 查找——线性表的折半法查找