-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBurstBallons.java
More file actions
41 lines (25 loc) · 765 Bytes
/
BurstBallons.java
File metadata and controls
41 lines (25 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.awt.image.ImageProducer;
public class BurstBallons {
public static int maxCoins(int[] nums) {
int n=nums.length+2;
int[] A=new int[n];
A[0]=A[n-1]=1;
for (int i = 0; i < nums.length; i++) {
A[i+1]=nums[i];
}
return getCoin(A,0,n-1);
}
private static int getCoin(int[] a, int left, int right) {
int max=0;
for (int i = left+1; i < right; i++) {
int score=a[left]*a[i]*a[right];
max=Math.max(max,score+getCoin(a,left,i)+getCoin(a,i,right));
}
return max;
}
public static void main(String[] args) {
int[] nums={3,1,5,8};
int res = maxCoins(nums);
System.out.println(res);
}
}