LeetCode - Burst Balloons

Posted 朽木の半夏

tags:

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

int max(int a,int b){
    if(a>b)return a;
    return b;
}
int maxCoins(int* nums, int numsSize) {
    int a[555];
    int n  = numsSize;
    int dp[555][555];
    memset(dp,0,sizeof(dp));
    for(int i = 1 ; i <= n ; i ++){
        a[i]=nums[i-1];
    }
    a[0] = a[n+1] = 1;
    for(int i = 1 ; i <= n ; i ++){
        dp[i][i] = a[i]*a[i-1]*a[i+1];
    }

    for(int k = 1 ; k <= n ; k ++){
        for(int i = 1 ; i + k <= n ; i ++){
            int l = i ;
            int r = i+k;

            for(int j = l ; j <= r ; j ++){
                dp[l][r] = max(dp[l][r],dp[i][j-1] + dp[j+1][r] + a[j]*a[l-1]*a[r+1]);
            }

        }
    }
    return dp[1][numsSize];
}
























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

[LeetCode] 312. Burst Balloons

LeetCode312. Burst Balloons

Leetcode 312. Burst Balloons

312. Burst Balloons - LeetCode

LeetCode-Burst Balloons

LeetCode - Burst Balloons