Skip to content

Commit 7f6d2b4

Browse files
authored
Create minimum-score-triangulation-of-polygon.py
1 parent 1390745 commit 7f6d2b4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n^3)
2+
# Space: O(n^2)
3+
4+
class Solution(object):
5+
def minScoreTriangulation(self, A):
6+
"""
7+
:type A: List[int]
8+
:rtype: int
9+
"""
10+
dp = [[0 for _ in xrange(len(A))] for _ in xrange(len(A))]
11+
for p in xrange(3, len(A)+1):
12+
for i in xrange(len(A)-p+1):
13+
j = i+p-1;
14+
dp[i][j] = float("inf")
15+
for k in xrange(i+1, j):
16+
dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j] + A[i]*A[j]*A[k]);
17+
return dp[0][-1]

0 commit comments

Comments
 (0)