Leetcode-5047 Minimum Score Triangulation of Polygon(多边形三角剖分的最低得分)

 1 const int maxn = 10000;
 2 #define _for(i,a,b) for(int i = (a);i < (b);i ++)
 3 typedef long long ll;
 4
 5
 6 class Solution
 7 {
 8     public:
 9         int t[60][60];
10         int s[60][60];
11         int weight[60];
12         int N;
13         int get_weight(const int a, const int b, const int c)
14         {
15             return weight[a] * weight[b] * weight[c];
16         }
17         int minScoreTriangulation(vector<int>& A)
18         {
19             int N = A.size();
20             _for(i,0,A.size())
21                 weight[i] = A[i];
22             int i,r,k,j;
23             int min;
24
25             for (i = 1; i < N; i++)
26             {
27                 t[i][i] = 0;
28             }
29
30             for (r = 2; r < N; r++)
31             {
32                 for (i = 1; i < N-r+1; i++)
33                 {
34                     j = i + r -1;
35                     min = INT_MAX;
36                     for (k = i; k < j; k++)
37                     {
38                         t[i][j] = t[i][k] + t[k+1][j] + get_weight(i-1,k,j);
39                         if (t[i][j] < min)
40                         {
41                             min = t[i][j];
42                             s[i][j] = k;
43                         }
44                     }
45                     t[i][j] = min;
46                 }
47             }
48             return t[1][N-1];
49         }
50 };

多边形三角剖分,DP走起来

原文地址:https://www.cnblogs.com/Asurudo/p/10812281.html

时间: 2024-12-31 06:18:59

Leetcode-5047 Minimum Score Triangulation of Polygon(多边形三角剖分的最低得分)的相关文章

LeetCode 1039. Minimum Score Triangulation of Polygon

原题链接在这里:https://leetcode.com/problems/minimum-score-triangulation-of-polygon/ 题目: Given N, consider a convex N-sided polygon with vertices labelled A[0], A[i], ..., A[N-1] in clockwise order. Suppose you triangulate the polygon into N-2 triangles.  F

【leetcode】1039. Minimum Score Triangulation of Polygon

题目如下: Given N, consider a convex N-sided polygon with vertices labelled A[0], A[i], ..., A[N-1] in clockwise order. Suppose you triangulate the polygon into N-2 triangles.  For each triangle, the value of that triangle is the product of the labels of

LeetCode --- 64. Minimum Path Sum

题目链接:Minimum Path Sum Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time. 这道题的要求是在m*n

【Leetcode】Minimum Path Sum

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time. 思路:简单的动态规划题目,设f(m, n)为从(0, 0)到达(m

【leetcode】Minimum Window Substring

问题: 给定两个字符串,S,T,返回S中包含T中所有字符的最短的字串,若不存在,则返回"".时间复杂度为O(n). 例如:S = "ADOBCODEBANC" T = "ABC" 返回BANC 生活场景: 把问题具体化现实化一点.有n层楼,每层楼里放有一个物品,现在老板给你一个物品清单,里面是要你集齐的物品,你可以乘坐电梯,但是电梯只停一次,停在哪一层,就从哪一层开始向楼上搜集物品,至于要在那层停电梯,由你自己选择. 这里我们当然选择即能集齐物品

LeetCode OJ - Minimum &amp;&amp; Maximum Depth of Binary Tree

这两道题用递归的解法都很简单,只是稍有不同. 下面是AC代码: 1 /** 2 * Given a binary tree, find its minimum depth. 3 * the minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 4 * @param root 5 * @return 6 */ 7 public in

【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 递归和非递归,此提比较简单.广度优先遍历即可.关键之处就在于如何保持访问深度. 下面是4种代码: 1

LeetCode | 0452. Minimum Number of Arrows to Burst Balloons用最少数量的箭引爆气球【Python】

LeetCode 0452. Minimum Number of Arrows to Burst Balloons用最少数量的箭引爆气球[Medium][Python][区间贪心] Problem LeetCode There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of

带洞多边形三角剖分

任意多边形三角剖分. 出售源码,价格私聊. 联系方式:微信 sunjingchao923       QQ 330363210 测试工程下载地址:腾讯微云 原文地址:https://www.cnblogs.com/thinkpore/p/11493349.html