[cf1140D. Minimum Triangulation][dp]
2 seconds
256 megabytes
standard input
standard output
You are given a regular polygon with nn vertices labeled from 11 to nn in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair of triangles such that their intersection has non-zero area, and the total area of all triangles is equal to the area of the given polygon. The weight of a triangulation is the sum of weigths of triangles it consists of, where the weight of a triagle is denoted as the product of labels of its vertices.
Calculate the minimum weight among all triangulations of the polygon.
The first line contains single integer nn (3≤n≤5003≤n≤500) — the number of vertices in the regular polygon.
Print one integer — the minimum weight among all triangulations of the given polygon.
3
6
4
18
According to Wiki: polygon triangulation is the decomposition of a polygonal area (simple polygon) PP into a set of triangles, i. e., finding a set of triangles with pairwise non-intersecting interiors whose union is PP.
In the first example the polygon is a triangle, so we don't need to cut it further, so the answer is 1⋅2⋅3=61⋅2⋅3=6.
In the second example the polygon is a rectangle, so it should be divided into two triangles. It's optimal to cut it using diagonal 1−31−3 so answer is 1⋅2⋅3+1⋅3⋅4=6+12=181⋅2⋅3+1⋅3⋅4=6+12=18.
题意:求将一个n边形分解成(n-2)个三边形花费的最小精力,其中花费的精力是所有三角形的三顶点编号乘积的和(其中编号是按照顶点的顺时针顺序编写的)
题解:dp[i][j]表示从顶点i到j区间内需要花费的最小精力,则参照floyd通过找中介点更新dp数组的方式更新dp数组即可
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout<<"["<<#x<<"]"<<" "<<x<<endl;
ll dp[][];
const ll inf=1e17;
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(abs(i-j)<=)dp[i][j]=;
else dp[i][j]=inf;
}
}
for(int k=;k<=n;k++){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]+i*j*k);
}
}
}
printf("%lld\n",dp[][n]);
return ;
}
[cf1140D. Minimum Triangulation][dp]的更多相关文章
- 题解 CF1140D 【Minimum Triangulation】
题意:求将一个n边形分解成(n-2)个三边形花费的最小精力,其中花费的精力是所有三角形的三顶点编号乘积的和(其中编号是按照顶点的顺时针顺序编写的) 考虑1,x,y连了一个三角形,x,y,z连了一个三角 ...
- uva 1331 - Minimax Triangulation(dp)
option=com_onlinejudge&Itemid=8&page=show_problem&category=514&problem=4077&mosm ...
- Codeforces1140D. Minimum Triangulation
题目链接 本题是区间dp里的三角剖分,板子题,dp[i][j]表示凸多边形i-j构成的最值,转移方程为dp[i][j] = min/max(dp[i][k]+dp[k][j]+w[i,j,k])(i& ...
- Atcoder Grand Contest 030 F - Permutation and Minimum(DP)
洛谷题面传送门 & Atcoder 题面传送门 12 天以前做的题了,到现在才补/yun 做了一晚上+一早上终于 AC 了,写篇题解纪念一下 首先考虑如果全是 \(-1\) 怎么处理.由于我 ...
- 【AGC030F】Permutation and Minimum(DP)
题目链接 题解 首先可以想到分组后,去掉两边都填了数的组. 然后就会剩下\((-1,-1)\)和\((-1,x)\)或\((x,-1)\)这两种情况 因为是最小值序列的情况数,我们可以考虑从大到小填数 ...
- LeetCode 1039. Minimum Score Triangulation of Polygon
原题链接在这里:https://leetcode.com/problems/minimum-score-triangulation-of-polygon/ 题目: Given N, consider ...
- UVA-1331 Minimax Triangulation 区间dp 计算几何 三角剖分 最大三角形最小化
题目链接:https://cn.vjudge.net/problem/UVA-1331 题意 给一个任意多边形,把它分为多个三角形. 求某方案中最大的三角形是各方案中最小的面积的三角形面积. 思路 学 ...
- codeforces 1140D(区间dp/思维题)
D. Minimum Triangulation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Educational Codeforces Round 62 (Rated for Div. 2) Solution
最近省队前联考被杭二成七南外什么的吊锤得布星,拿一场Div. 2恢复信心 然后Div.2 Rk3.Div. 1+Div. 2 Rk9,rating大涨200引起舒适 现在的Div. 2都怎么了,最难题 ...
随机推荐
- scau 9502 ARDF一个变量的问题
哨兵变量flag不小心没 设置成0..所以一直WA 9502 ARDF 时间限制:1000MS 内存限制:65535K 提交次数:0 通过次数:0 题型: 编程题 语言: G++;GCC Des ...
- 欧拉图Eulerian Graph
一.节点的度 无向图:节点的度为该节点所连接的边数 有向图:节点的度分为入度和出度. 二.欧拉图定义 具有欧拉回路的图称作欧拉图,具有欧拉路径而无欧拉回路的图称为半欧拉图. 欧拉回路: 通过图中每 ...
- Android去评分,分享
去评分: 跳到手机中已安装的市场评分页面 Uri uri = Uri.parse("market://details?id="+getPackageName()); Intent ...
- Docker 学习笔记(三):数据、网络、系统权限、docker-compose
一.Docker 数据管理 Docker 持久化数据有两种方式: 使用数据卷:更安全,和主机耦合度低 将主机的目录挂载到容器中:更方便,主机和容器可以很方便地交换数据. 数据卷相关的命令: docke ...
- 1.sql统计语句
select exam_item_code, exam_item, EXAMDATE, count(distinct patient_id) from (select t2.exam_item_cod ...
- ASCII,UTF-8,Unicode字符串相互转换
#include<string> #include<windows.h> #include<vector> using namespace std; //utf8 ...
- 使用MD5加密字符串
一.概念: MD5码以512位分组来处理输入的信息,且每一分组又被划分为16个32位子分组,经过了一系列的处理后,算法的输出由四个32位分组组成,将这四个32位分组级联后将生成一个128位散列值. 二 ...
- C#合并选中EXCEL中的各个工作表
合并选中EXCEL中的各个工作表,以第一个选中的EXCEL文件里的工作表进行匹配,遍历后面的每个EXCEL文件,有相同的工作表就合并: private void button1_Click(objec ...
- Java内存模型之总结
经过四篇博客阐述,我相信各位对Java内存模型有了最基本认识了,下面LZ就做一个比较简单的总结. 总结 JMM规定了线程的工作内存和主内存的交互关系,以及线程之间的可见性和程序的执行顺序.一方面,要为 ...
- 如何设置MySql Server远程访问(Debian Linux)
1. 登录Mysql Server: $mysql -u root -p 2. 检查网络,Server是否允许远程连接: mysql> show variables like '%skip_ne ...