区间$dp$,四边形优化。

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. #include<vector>
  7. #include<map>
  8. #include<set>
  9. #include<queue>
  10. #include<stack>
  11. #include<ctime>
  12. #include<iostream>
  13. using namespace std;
  14. typedef long long LL;
  15. const double pi=acos(-1.0),eps=1e-;
  16. void File()
  17. {
  18. freopen("D:\\in.txt","r",stdin);
  19. freopen("D:\\out.txt","w",stdout);
  20. }
  21. template <class T>
  22. inline void read(T &x)
  23. {
  24. char c = getchar();
  25. x = ;
  26. while(!isdigit(c)) c = getchar();
  27. while(isdigit(c))
  28. {
  29. x = x * + c - '';
  30. c = getchar();
  31. }
  32. }
  33.  
  34. int n;
  35. int x[],y[],dp[][],f[][];
  36.  
  37. int main()
  38. {
  39. while(~scanf("%d",&n))
  40. {
  41. for(int i=;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
  42. if(n==) { printf("0\n"); continue; }
  43.  
  44. for(int i=;i<=n;i++) dp[i][i]=;
  45. for(int i=;i<n;i++)
  46. {
  47. dp[i][i+]=y[i]-y[i+]+x[i+]-x[i];
  48. f[i][i+]=i;
  49. }
  50.  
  51. for(int len=;len<=n;len++)
  52. {
  53. for(int st=;st<=n&&st+len-<=n;st++)
  54. {
  55. int en=st+len-;
  56. dp[st][en]=0x7FFFFFFF;
  57. for(int j=f[st][en-];j<=f[st+][en];j++)
  58. {
  59. if(dp[st][j]+dp[j+][en]+y[j]-y[en]+x[j+]-x[st]<dp[st][en])
  60. {
  61. dp[st][en]=dp[st][j]+dp[j+][en]+y[j]-y[en]+x[j+]-x[st];
  62. f[st][en]=j;
  63. }
  64. }
  65. }
  66. }
  67.  
  68. printf("%d\n",dp[][n]);
  69. }
  70. return ;
  71. }

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. WIndows 相关知识

    Windows服务 图解WinXP局域网共享设置步骤 Win10如何搭建FTP服务器以实现快速传输文件 强大工具psexec工具用法简介 BIOS和CMOS的区别 系统CLSID简介和小技巧

  2. 洛谷 P1415 拆分数列 解题报告

    拆分数列 题目背景 [为了响应党中央勤节俭.反铺张的精神,题目背景描述故事部分略去^-^] 题目描述 给出一列数字,需要你添加任意多个逗号将其拆成若干个严格递增的数. 如果有多组解,则输出使得最后一个 ...

  3. spring事务不回滚 自己抛的异常

    在service代码中   throw new Excepion("自定义异常“) 发现没有回滚, 然后百度了下, 改为抛出运行时异常  throw new RuntimeException ...

  4. js 扒一扒这些题目都考了哪些知识点

    1.空数组是true还是false 题目: <script> var tmp = 'a'; if([]==false) tmp+='b'; if(![]) tmp +='c'; alert ...

  5. SSL步骤

    SSL步骤 被认证的服务器 1.创建keystore 2.创建信任证书 3.导出信任证书供客户端使用 客户端 1.创建keystore(如果不存在) 2.导入信任证书

  6. 【BZOJ1468】Tree [点分治]

    Tree Time Limit: 10 Sec  Memory Limit: 64 MB[Submit][Status][Discuss] Description 给你一棵TREE,以及这棵树上边的距 ...

  7. 【BZOJ】1571: [Usaco2009 Open]滑雪课Ski

    [算法]动态规划 [题解]yy出了O(1w log 1w)的算法. 将雪坡排序预处理出g[i]表示能力值为i的最短时长雪坡. 这样就可以定义work(t,c)表示时长t能力c的最多滑雪数量,work( ...

  8. 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 ...

  9. Makefile之大型工程项目子目录Makefile的一种通用写法【转】

    转自:http://www.cnblogs.com/skyofbitbit/p/3680753.html 管理Linux环境下的C/C++大型项目,如果有一个智能的Build System会起到事半功 ...

  10. cpu_relax( )-----对自选循环等待(spin-wait loops)操作的优化【转】

    cpu_relax()-----对自选循环等待(spin-wait loops)操作的优化 转自:http://www.doc100.net/bugs/t/173547/index.html 在loc ...