区间$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的更多相关文章

  1. HDU 3516 Tree Construction (四边形不等式)

    题意:给定一些点(xi,yi)(xj,yj)满足:i<j,xi<xj,yi>yj.用下面的连起来,使得所有边的长度最小? 思路:考虑用区间表示,f[i][j]表示将i到j的点连起来的 ...

  2. HDU.3516.Tree Construction(DP 四边形不等式)

    题目链接 贴个教程: 四边形不等式学习笔记 \(Description\) 给出平面上的\(n\)个点,满足\(X_i\)严格单增,\(Y_i\)严格单减.以\(x\)轴和\(y\)轴正方向作边,使这 ...

  3. HDOJ 3516 Tree Construction

    四边形优化DP Tree Construction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  4. 【HDU】3516 Tree Construction

    http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意:平面n个点且满足xi<xj, yi>yj, i<j.xi,yi均为整数.求一棵树边 ...

  5. HDOJ 3516 Tree Construction 四边形优化dp

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意: 大概就是给你个下凸包的左侧,然后让你用平行于坐标轴的线段构造一棵树,并且这棵树的总曼哈顿 ...

  6. 数据结构 - Codeforces Round #353 (Div. 2) D. Tree Construction

    Tree Construction Problem's Link ------------------------------------------------------------------- ...

  7. HDU 5813 Elegant Construction(优雅建造)

    HDU 5813 Elegant Construction(优雅建造) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65 ...

  8. codeforces 675D D. Tree Construction(线段树+BTS)

    题目链接: D. Tree Construction D. Tree Construction time limit per test 2 seconds memory limit per test ...

  9. hdu 5909 Tree Cutting [树形DP fwt]

    hdu 5909 Tree Cutting 题意:一颗无根树,每个点有权值,连通子树的权值为异或和,求异或和为[0,m)的方案数 \(f[i][j]\)表示子树i中经过i的连通子树异或和为j的方案数 ...

随机推荐

  1. [洛谷P1337][JSOI2004]平衡点 / 吊打XXX

    题目大意:有$n$个重物,每个重物系在一条绳子上.所有绳子系在一起,问绳结最终平衡于何处. 题解:$NOIP$前学学模拟退火,但发现我脸好黑啊... 卡点:脸黑 C++ Code: #include ...

  2. [POI2007]ATR-Tourist Attractions

    题目大意:一个无向图,从$1$到$n$,要求必须经过$2,3,\dots,k+1$,给出一些限制关系,要求在经过$v\leq k+1$之前必须经过$u\leq k+1$,求最短路 题解:预处理出$1\ ...

  3. linux kernel 关于RSS/RPS/RFS/XPS的介绍

    Introduction============ This document describes a set of complementary techniques in the Linuxnetwo ...

  4. [Leetcode] remove element 删除元素

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  5. 【POJ 1201 Intervals】

    Time Limit: 2000MSMeamory Limit: 65536K Total Submissions: 27949Accepted: 10764 Description You are ...

  6. Ajax缓存问题怎么解决?

    项目有时要用一些Ajax的效果,因为比较简单,也就没有去用什么Ajax.net之类的东西,手写代码也就实现了.第二天,有人向我报告错误:说是只有第一次读取的值正常,后面的值都不正常:我调试了一下 ,确 ...

  7. There is an overlap in the region chain修复

    ERROR: (region day_hotstatic,860010-2355010000_20140417_12_entry_00000000321,1400060700465.fda3b0aca ...

  8. 线程 ManualResetEvent 类

    Reset(): 当一个线程开始一个活动(此活动必须完成后,其他线程才能开始)时, 它调用 Reset 以将 ManualResetEvent 置于非终止状态.此线程可被视为控制 ManualRese ...

  9. 利用saltstack初始化OpenStack服务器环境

    目录架构图如上图所示 sls脚本详情如下: Sync_Host: file.managed: - name: /etc/hosts - source: salt://state/files/hosts ...

  10. 【CF103D】Time to Raid Cowavans(分块)

    题意: 思路:院赛防AK题,然而还没来得及做就被数据出锅的题坑了…… #include<cstdio> #include<cstring> #include<string ...