312. Burst Balloons

Posted 我的名字叫周周

tags:

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

     /*
      * 312. Burst Balloons
      * 2016-7-4 by Mingyang
      */
     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 left = 0; left < n - k; ++left) {
                    int right = left + k;
                    for (int i = left + 1; i < right; ++i)
                        dp[left][right] = Math.max(dp[left][right], 
                        nums[left] * nums[i] * nums[right] + dp[left][i] + dp[i][right]);
                }

            return dp[0][n - 1];
        }

 

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

[leetcode-312-Burst Balloons]

[LeetCode] 312. Burst Balloons

LeetCode312. Burst Balloons

312. Burst Balloons

Leetcode 312. Burst Balloons

java 312. Burst Balloons(Recursive).java