-
Notifications
You must be signed in to change notification settings - Fork 160
/
burst-balloons.md
19 lines (14 loc) · 1.08 KB
/
burst-balloons.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<p>Given <code>n</code> balloons, indexed from <code>0</code> to <code>n-1</code>. Each balloon is painted with a number on it represented by array <code>nums</code>. You are asked to burst all the balloons. If the you burst balloon <code>i</code> you will get <code>nums[left] * nums[i] * nums[right]</code> coins. Here <code>left</code> and <code>right</code> are adjacent indices of <code>i</code>. After the burst, the <code>left</code> and <code>right</code> then becomes adjacent.</p>
<p>Find the maximum coins you can collect by bursting the balloons wisely.</p>
<p><b>Note:</b></p>
<ul>
<li>You may imagine <code>nums[-1] = nums[n] = 1</code>. They are not real therefore you can not burst them.</li>
<li>0 ≤ <code>n</code> ≤ 500, 0 ≤ <code>nums[i]</code> ≤ 100</li>
</ul>
<p><b>Example:</b></p>
<pre>
<b>Input:</b> <code>[3,1,5,8]</code>
<b>Output:</b> <code>167
<strong>Explanation: </strong></code>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
</pre>