-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleet-code-q-33.java
More file actions
24 lines (20 loc) · 905 Bytes
/
leet-code-q-33.java
File metadata and controls
24 lines (20 loc) · 905 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
class Solution {
public int minScoreTriangulation(int[] polygonValues) {
int vertexCount = polygonValues.length;
int[][] minScore = new int[vertexCount][vertexCount];
for (int gap = 2; gap < vertexCount; gap++) {
for (int start = 0; start + gap < vertexCount; start++) {
int end = start + gap;
int currentMinScore = Integer.MAX_VALUE;
for (int mid = start + 1; mid < end; mid++) {
int triangleScore = minScore[start][mid]
+ minScore[mid][end]
+ polygonValues[start] * polygonValues[mid] * polygonValues[end];
currentMinScore = Math.min(currentMinScore, triangleScore);
}
minScore[start][end] = currentMinScore;
}
}
return minScore[0][vertexCount - 1];
}
}