[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都怎么了,最难题 ...
随机推荐
- Ubuntu下U盘文件只读的解决办法
转自linux公社:http://www.linuxidc.com/Linux/2012-12/76130.htm Ubuntu下U盘出现文件系统只读的问题了.症状为无法删除U盘中现有文件,无法向U盘 ...
- LeetCode 414. 第三大的数(Third Maximum Number) 3
414. 第三大的数 414. Third Maximum Number 题目描述 给定一个非空数组,返回此数组中第三大的数.如果不存在,则返回数组中最大的数.要求算法时间复杂度必须是 O(n). 每 ...
- Recurrent neural network (RNN) - Pytorch版
import torch import torch.nn as nn import torchvision import torchvision.transforms as transforms # ...
- 转:如何正确彻底删除webpack 全局或是局部?
原文链接:如何正确彻底删除webpack 全局或是局部? 就需要卸载cli 配置webpack ,提示需要安装 webpack-cli,选择yes 后安装webpack-cli , 可是问题不断,所以 ...
- Android广播机制——初体验
写在前面的话 文章为笔者自己理解 . -如有错误,欢迎指正- <第一行代码>读书笔记 写于2017年10月16日17:00:40 (一). 安卓广播的分类 a.标准广播 标准广播发出以后, ...
- VNC的使用
1. 安装 rpm -ivh tigervnc-server--.el6.x86_64.rpm 如果rpm安装时发现有依赖,建议直接使用yum安装,轻松解决依赖问题: yum install tige ...
- Hibernate常用api以及增删改查
一 .API的定义 所谓的API全称就是(Application Programming Interface,应用程序编程接口).就是类库对外提供的接口.类.枚举.注解等元素. 如:JDK API ...
- Educational Codeforces Round 65 (Div. 2)
A.前n-10个有8即合法. #include<cstdio> #include<cstring> #include<iostream> #include<a ...
- C# 用Redis实现的分布式锁
Redis实现分布式锁(悲观锁/乐观锁) 对锁的概念和应用场景在此就不阐述了,网上搜索有很多解释,只是我搜索到的使用C#利用Redis的SetNX命令实现的锁虽然能用,但是都不太适合我需要的场景. 基 ...
- 用ajax和PHP实现简单的流程管理
首先要先有一个新建流程的页面xinjian.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...