Burst Balloons
You are given n balloons, each painted with a number in the array nums. Bursting balloon i earns nums[i-1] * nums[i] * nums[i+1] coins, where out-of-range neighbors are treated as a balloon with value 1. After a balloon bursts, its neighbors become adjacent. Return the maximum coins you can collect by bursting all balloons in an optimal order.
Open official problem prompt ↗Find the maximum total coins from bursting every balloon, given that each burst's payout depends on whichever balloons are currently adjacent.
Think of a fireworks finale: instead of planning which shell to fire first, you plan which shell fires LAST in each section of the sky. Once you fix the last shell, the sky splits into two independent sections you can plan separately.
- Input
- nums = [3, 1, 5, 8]
- Output
- 167
- Why
- Bursting in order 1,5,3,8 yields 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 15+120+24+8 = 167.
n == nums.length1 <= n <= 3000 <= nums[i] <= 100