HDU 3516 Tree Construction
区间$dp$,四边形优化。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} int n;
int x[],y[],dp[][],f[][]; int main()
{
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
if(n==) { printf("0\n"); continue; } for(int i=;i<=n;i++) dp[i][i]=;
for(int i=;i<n;i++)
{
dp[i][i+]=y[i]-y[i+]+x[i+]-x[i];
f[i][i+]=i;
} for(int len=;len<=n;len++)
{
for(int st=;st<=n&&st+len-<=n;st++)
{
int en=st+len-;
dp[st][en]=0x7FFFFFFF;
for(int j=f[st][en-];j<=f[st+][en];j++)
{
if(dp[st][j]+dp[j+][en]+y[j]-y[en]+x[j+]-x[st]<dp[st][en])
{
dp[st][en]=dp[st][j]+dp[j+][en]+y[j]-y[en]+x[j+]-x[st];
f[st][en]=j;
}
}
}
} printf("%d\n",dp[][n]);
}
return ;
}
HDU 3516 Tree Construction的更多相关文章
- HDU 3516 Tree Construction (四边形不等式)
题意:给定一些点(xi,yi)(xj,yj)满足:i<j,xi<xj,yi>yj.用下面的连起来,使得所有边的长度最小? 思路:考虑用区间表示,f[i][j]表示将i到j的点连起来的 ...
- HDU.3516.Tree Construction(DP 四边形不等式)
题目链接 贴个教程: 四边形不等式学习笔记 \(Description\) 给出平面上的\(n\)个点,满足\(X_i\)严格单增,\(Y_i\)严格单减.以\(x\)轴和\(y\)轴正方向作边,使这 ...
- HDOJ 3516 Tree Construction
四边形优化DP Tree Construction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- 【HDU】3516 Tree Construction
http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意:平面n个点且满足xi<xj, yi>yj, i<j.xi,yi均为整数.求一棵树边 ...
- HDOJ 3516 Tree Construction 四边形优化dp
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意: 大概就是给你个下凸包的左侧,然后让你用平行于坐标轴的线段构造一棵树,并且这棵树的总曼哈顿 ...
- 数据结构 - Codeforces Round #353 (Div. 2) D. Tree Construction
Tree Construction Problem's Link ------------------------------------------------------------------- ...
- HDU 5813 Elegant Construction(优雅建造)
HDU 5813 Elegant Construction(优雅建造) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65 ...
- codeforces 675D D. Tree Construction(线段树+BTS)
题目链接: D. Tree Construction D. Tree Construction time limit per test 2 seconds memory limit per test ...
- hdu 5909 Tree Cutting [树形DP fwt]
hdu 5909 Tree Cutting 题意:一颗无根树,每个点有权值,连通子树的权值为异或和,求异或和为[0,m)的方案数 \(f[i][j]\)表示子树i中经过i的连通子树异或和为j的方案数 ...
随机推荐
- 解决IIS的Server Application Error
问题描述一下: Server Application ErrorThe server has encountered an error while loading an application dur ...
- NOIP2010 引水入城 贪心+DFS
我们先把简单的不能搞死,具题意可证:每个蓄水长的管辖区域一定是连续的.证明:既然我们已经能了那么我们就可以说如果这个区间不是连续的那我们取出这个区间中间阻隔开的那一段,那么对于这一整个区间来说水源不可 ...
- 实际上ECMAScript中并没有对类的定义
首先,我们用一个经典例子来简单阐述一下ECMAScript中的继承机制. 在几何学上,实质上几何形状只有两种,即椭圆形(是圆形的)和多边形(具有一定数量的边).圆是椭圆的一种,它只有一个焦点.三角形. ...
- WCF分布式开发步步为赢(13):WCF服务离线操作与消息队列MSMQ
之前曾经写过一个关于MSMQ消息队列的文章:WCF分布式开发必备知识(1):MSMQ消息队列 ,当时的目的也是用它来作为学习WCF 消息队列MSMQ编程的基础文章.在那篇文章里,我们详细介绍了MSMQ ...
- Tile Cut~网络流入门题
Description When Frodo, Sam, Merry, and Pippin are at the Green Dragon Inn drinking ale, they like t ...
- php spl库的使用(PHP标准库)【摘抄引用】
文章来源与推荐阅读:阮一峰--PHP SPL笔记 && PHP SPL使用方法和他的威力 1.SPL 是什么? SPL:standard php library php标准库,此 ...
- [Python]简单的外星人入侵游戏
alien_invasion.py: import sys import pygame from setting import Settings from ship import Ship impor ...
- Android4.4中WebView无法显示图片解决方案
在Android4.4之前我们在使用WebView时为了提高加载速度我设置了(myWebView.getSettings().setBlockNetworkImage(true);//图片加载放在最后 ...
- 状压dp的题目列表 (一)
状压dp的典型的例子就是其中某个数值较小. 但是某个数值较小也不一定是状压dp,需要另外区分的一种题目就是用暴力解决的题目,例如UVA818 紫书215 题目列表: ①校长的烦恼 UVA10817 紫 ...
- HDU 2036 改革春风吹满地 (数学)
题目链接 Problem Description " 改革春风吹满地, 不会AC没关系; 实在不行回老家, 还有一亩三分地. 谢谢!(乐队奏乐)" 话说部分学生心态极好,每天就知道 ...