0


Python | Leetcode Python题解之第312题戳气球

题目:

题解:

class Solution:
    def maxCoins(self, nums: List[int]) -> int:
        n = len(nums)
        rec = [[0] * (n + 2) for _ in range(n + 2)]
        val = [1] + nums + [1]

        for i in range(n - 1, -1, -1):
            for j in range(i + 2, n + 2):
                for k in range(i + 1, j):
                    total = val[i] * val[k] * val[j]
                    total += rec[i][k] + rec[k][j]
                    rec[i][j] = max(rec[i][j], total)
        
        return rec[0][n + 1]
标签: Python Leetcode 题解

本文转载自: https://blog.csdn.net/Mopes__/article/details/140861949
版权归原作者 Mopes__ 所有, 如有侵权,请联系我们删除。

“Python | Leetcode Python题解之第312题戳气球”的评论:

还没有评论