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的方案数 ...
随机推荐
- WIndows 相关知识
Windows服务 图解WinXP局域网共享设置步骤 Win10如何搭建FTP服务器以实现快速传输文件 强大工具psexec工具用法简介 BIOS和CMOS的区别 系统CLSID简介和小技巧
- 洛谷 P1415 拆分数列 解题报告
拆分数列 题目背景 [为了响应党中央勤节俭.反铺张的精神,题目背景描述故事部分略去^-^] 题目描述 给出一列数字,需要你添加任意多个逗号将其拆成若干个严格递增的数. 如果有多组解,则输出使得最后一个 ...
- spring事务不回滚 自己抛的异常
在service代码中 throw new Excepion("自定义异常“) 发现没有回滚, 然后百度了下, 改为抛出运行时异常 throw new RuntimeException ...
- js 扒一扒这些题目都考了哪些知识点
1.空数组是true还是false 题目: <script> var tmp = 'a'; if([]==false) tmp+='b'; if(![]) tmp +='c'; alert ...
- SSL步骤
SSL步骤 被认证的服务器 1.创建keystore 2.创建信任证书 3.导出信任证书供客户端使用 客户端 1.创建keystore(如果不存在) 2.导入信任证书
- 【BZOJ1468】Tree [点分治]
Tree Time Limit: 10 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description 给你一棵TREE,以及这棵树上边的距 ...
- 【BZOJ】1571: [Usaco2009 Open]滑雪课Ski
[算法]动态规划 [题解]yy出了O(1w log 1w)的算法. 将雪坡排序预处理出g[i]表示能力值为i的最短时长雪坡. 这样就可以定义work(t,c)表示时长t能力c的最多滑雪数量,work( ...
- POJ 3617 Best Cow Line (模拟)
题目链接 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Yea ...
- Makefile之大型工程项目子目录Makefile的一种通用写法【转】
转自:http://www.cnblogs.com/skyofbitbit/p/3680753.html 管理Linux环境下的C/C++大型项目,如果有一个智能的Build System会起到事半功 ...
- cpu_relax( )-----对自选循环等待(spin-wait loops)操作的优化【转】
cpu_relax()-----对自选循环等待(spin-wait loops)操作的优化 转自:http://www.doc100.net/bugs/t/173547/index.html 在loc ...