1039. Minimum Score Triangulation of Polygon Medium
1/**
2 * [1039] Minimum Score Triangulation of Polygon
3 *
4 * You have a convex n-sided polygon where each vertex has an integer value. You are given an integer array values where values[i] is the value of the i^th vertex (i.e., clockwise order).
5 * You will triangulate the polygon into n - 2 triangles. For each triangle, the value of that triangle is the product of the values of its vertices, and the total score of the triangulation is the sum of these values over all n - 2 triangles in the triangulation.
6 * Return the smallest possible total score that you can achieve with some triangulation of the polygon.
7 *
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2021/02/25/shape1.jpg" style="width: 201px; height: 133px;" />
10 * Input: values = [1,2,3]
11 * Output: 6
12 * Explanation: The polygon is already triangulated, and the score of the only triangle is 6.
13 *
14 * Example 2:
15 * <img alt="" src="https://assets.leetcode.com/uploads/2021/02/25/shape2.jpg" style="width: 446px; height: 163px;" />
16 * Input: values = [3,7,4,5]
17 * Output: 144
18 * Explanation: There are two triangulations, with possible scores: 3*7*5 + 4*5*7 = 245, or 3*4*5 + 3*4*7 = 144.
19 * The minimum score is 144.
20 *
21 * Example 3:
22 * <img alt="" src="https://assets.leetcode.com/uploads/2021/02/25/shape3.jpg" style="width: 207px; height: 163px;" />
23 * Input: values = [1,3,1,4,1,5]
24 * Output: 13
25 * Explanation: The minimum score triangulation has score 1*1*3 + 1*1*4 + 1*1*5 + 1*1*1 = 13.
26 *
27 *
28 * Constraints:
29 *
30 * n == values.length
31 * 3 <= n <= 50
32 * 1 <= values[i] <= 100
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/minimum-score-triangulation-of-polygon/
38// discuss: https://leetcode.com/problems/minimum-score-triangulation-of-polygon/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn min_score_triangulation(values: Vec<i32>) -> i32 {
44 0
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_1039() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.