dp
with dimensions n x n
to store the minimum score for sub-polygons, where n
is the number of vertices in the polygon.dp
array with default values (e.g., -1 or INT_MAX
) to indicate that the subproblem has not been solved yet.minScore
that takes the indices i
and j
as arguments, representing the vertices of the sub-polygon.i + 1 == j
, there are only two vertices, and no triangle can be formed, so return 0.dp[i][j]
is not the default value, return dp[i][j]
as the subproblem has already been solved.k
between i
and j
and calculate the score for the triangle formed by vertices i
, j
, and k
, and add the minimum scores of the two sub-polygons formed by the diagonal (i, k)
and (k, j)
.dp[i][j]
with the minimum score found.dp[i][j]
as the minimum score for the sub-polygon defined by vertices i
and j
.