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的方案数 ...
随机推荐
- 《软件调试的艺术》学习笔记——GDB使用技巧摘要
<软件调试的艺术>学习笔记——GDB使用技巧摘要 <软件调试的艺术>,因为名是The Art of Debugging with GDB, DDD, and Eclipse. ...
- 部分经典IT书籍
部分经典IT书籍 [系统,网路管理]1) Learning the Unix Operating System 1565923901 O'reilly/1997-4ed ***强力推荐给想入门unix ...
- [spoj DISUBSTR]后缀数组统计不同子串个数
题目链接:https://vjudge.net/contest/70655#problem/C 后缀数组的又一神奇应用.不同子串的个数,实际上就是所有后缀的不同前缀的个数. 考虑所有的后缀按照rank ...
- 安卓titlebar的组合控件使用
http://blog.csdn.net/itachi85/article/details/51435187
- Saruman’s Level Up~(多校赛算组合数)
Description Saruman’s army of orcs and other dark minions continuously mine and harvest lumber out o ...
- Qt5 界面中文乱码问题
1.文件所在项目文件 xxx.pro 中添加: QMAKE_CXXFLAGS += -execution-charset:utf- 2.文件以 UTF-8 编码保存 3.添加 utf-8 BOM
- 播放video
<html> <head> <title> four in one vedio</title> <style type="text/cs ...
- HDU1863 畅通工程---(最小生成树)
畅通工程 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 【BZOJ1419】 Red is good [期望DP]
Red is good Time Limit: 10 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description 桌面上有R张红牌和B张 ...
- [bzoj4602][Sdoi2016]齿轮——dfs
题目 现有一个传动系统,包含了N个组合齿轮和M个链条.每一个链条连接了两个组合齿轮u和v,并提供了一个传动比x : y.即如果只考虑这两个组合齿轮,编号为u的齿轮转动x圈,编号为v的齿轮会转动y圈.传 ...