HDOJ 3516 Tree Construction
四边形优化DP
Tree Construction
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 868 Accepted Submission(s): 470
an example tree.

Write a program that finds a tree connecting all given points with the shortest total length of edges.
5
1 5
2 4
3 3
4 2
5 1
1
10000 0
12
0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int maxn=1100;
const int INF=0x3f3f3f3f; struct POINT
{
int x,y;
}pt[maxn]; int n;
int dp[maxn][maxn],s[maxn][maxn]; inline int cost(int i,int j,int k)
{
return pt[k].y-pt[j].y+pt[k+1].x-pt[i].x;
} int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
{
scanf("%d%d",&pt[i].x,&pt[i].y);
}
for(int i=1;i<=n;i++)
{
s[i][i]=i;
}
for(int len=2;len<=n;len++)
{
for(int i=1;i+len-1<=n;i++)
{
int j=i+len-1;
dp[i][j]=INF;
for(int k=s[i][j-1];k<=s[i+1][j]&&k<j;k++)
{
if(dp[i][j]>dp[i][k]+dp[k+1][j]+cost(i,j,k))
{
s[i][j]=k;
dp[i][j]=dp[i][k]+dp[k+1][j]+cost(i,j,k);
}
}
}
}
printf("%d\n",dp[1][n]);
}
return 0;
}
HDOJ 3516 Tree Construction的更多相关文章
- HDOJ 3516 Tree Construction 四边形优化dp
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意: 大概就是给你个下凸包的左侧,然后让你用平行于坐标轴的线段构造一棵树,并且这棵树的总曼哈顿 ...
- 【HDU】3516 Tree Construction
http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意:平面n个点且满足xi<xj, yi>yj, i<j.xi,yi均为整数.求一棵树边 ...
- 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\)轴正方向作边,使这 ...
- HDU 3516 Tree Construction
区间$dp$,四边形优化. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio&g ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 数据结构 - Codeforces Round #353 (Div. 2) D. Tree Construction
Tree Construction Problem's Link ------------------------------------------------------------------- ...
- codeforces 675D D. Tree Construction(线段树+BTS)
题目链接: D. Tree Construction D. Tree Construction time limit per test 2 seconds memory limit per test ...
- Codeforces Round #353 (Div. 2) D. Tree Construction 模拟
D. Tree Construction 题目连接: http://www.codeforces.com/contest/675/problem/D Description During the pr ...
随机推荐
- C keyword register 并讨论共同使用嵌入式汇编
C keyword register 并讨论共同使用嵌入式汇编 register 是C99 的keyword之中的一个. register 是储存类型之中的一个.这里仅讨论register 储存类型. ...
- Windows 8 动手实验系列教程 实验5:进程生命周期管理
动手实验 实验5:进程生命周期管理 2012年9月 简介 进程生命周期管理对构建Windows应用商店应用的开发者来说是需要理解的最重要的概念之一.不同于传统的Windows应用(它们即使在后台仍然继 ...
- 设置静态IP
设定IP $sudo vi/etc/network/interfaces autolo iface lo inet loopback 加入下面内容 autoeth0 iface eth0inet st ...
- ListView+CheckBox两种解决方式及原因分析
近期在用ListView+CheckBox搞一个item选中的项目,我将CheckBox的focus设置为false,另我大喜的是,CheckBox居然能够选中(窃喜中),这么简单就搞定了,由于数据量 ...
- 关于iptables的u32匹配
前面一篇文章----阐释了iptables最新的bpf match,说它将多个matches并成了一个经过编译的解释型bytecode bpf match,早在bpf match之前,u32 matc ...
- MyBATIS使用CRUD
MyEclipse不提供自己主动生成,这里提供mybatis文件包和开发文档 http://download.csdn.net/detail/u010026901/7489319 自己建立配置文件, ...
- 深度学习系列之CNN核心内容
导读 怎么样来理解近期异常火热的深度学习网络?深度学习有什么亮点呢?答案事实上非常简答.今年十月份有幸參加了深圳高交会的中科院院士论坛.IEEE fellow汤晓欧做了一场精彩的报告,这个问题被汤大神 ...
- windows下搭建node.js及npm的工作环境
近期在研究数据可视化D3框架,决定在windows下搭建一个nodejs及npm的工作环境,在网上查了n篇文章,别管是编译源代码安装也好.还是使用node.msi格式安装包也好,总是有问题.终于,功夫 ...
- TControl的消息覆盖函数大全(15个WM_函数和17个CM_函数,它的WndProc就处理鼠标与键盘消息)
注意,这些函数只有Private一种形式(也就是不允许覆盖,但仍在动态表格中)(特别注意,这里居然没有WM_PAINT函数): TControl = class(TComponent) private ...
- [Android学习笔记]Bitmap,BitmapDrawable,BitmapFactory学习笔记
Bitmap:图片文件的封装,可以看做是一张位图此类中的静态方法可以通过源Bitmap创建新的Bitmap对象此类封装了位图的一些信息Bitmap文档 BitmapFactory:一个工具类,用于创建 ...