Burst Balloons

Posted keepshuatishuati

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Burst Balloons相关的知识,希望对你有一定的参考价值。

 1 public class Solution {
 2     public int maxCoins(int[] nums) {
 3         if (nums.length == 0) {
 4             return 0;
 5         }
 6         
 7         int[] bl = new int[nums.length + 2];
 8         int index = 1;
 9         for (int num : nums) {
10             if (num != 0) {
11                 bl[index++] = num;
12             }
13         }
14         bl[0] = 1;
15         bl[index++] = 1;
16         
17         int[][] dp = new int[index][index];
18         
19         for (int i = 2; i < index; i++) {
20             for (int left = 0; left < index - i; left++) {
21                 int right = left + i;
22                 for (int k = left + 1; k < right; k++) {
23                     dp[left][right] = Math.max(dp[left][right], dp[left][k] + dp[k][right] + bl[k] * bl[left] * bl[right]);
24                 }
25             }
26         }
27         return dp[0][index - 1];
28         
29     }
30 }

1. Make final balloon as the position i.

2. try to optimize the solution from (left , i - 1) to (i + 1, right).

3. Since it garantee to cover i position, right = left + i. right < index. So left < index - k.

 

以上是关于Burst Balloons的主要内容,如果未能解决你的问题,请参考以下文章

DP-Burst Balloons

312. Burst Balloons

[leetcode-312-Burst Balloons]

[LeetCode] 312. Burst Balloons

LeetCode312. Burst Balloons

Burst Balloons