Burst Balloons
Givennballoons, indexed from0ton-1. Each balloon is painted with a number on it represented by arraynums. You are asked to burst all the balloons. If the you burst ballooniyou will getnums[left] * nums[i] * nums[right]coins. Hereleftandrightare adjacent indices ofi. After the burst, theleftandrightthen becomes adjacent.
Find the maximum coins you can collect by bursting the balloons wisely.
Note:
You may imagine
nums[-1] = nums[n] = 1. They are not real therefore you can not burst them.
0 ≤
n≤ 500, 0 ≤
nums[i]≤ 100
Example:
Input:
[3,1,5,8]
Output:
167
Explanation:
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分析
区间内气球全部消掉,所以区间内loop数和区间外头尾*
数组前后延长1考虑边界
Last updated
Was this helpful?