OvO http://codeforces.com/contest/838/problem/E

  (IndiaHacks 2nd Elimination 2017 (unofficial, unrated mirror, ICPC rules) - E)

  dp[i][j][k]表示左端点为i,右端点为j这个区间(如果i>j,就是(i~n),(1,j)),状态为k(k=0说明i这端可以接,k=1说明j这端可以接)

  枚举长度,

  那么对于dp[i][j][0],可以从dp[i-1][j][0]接上i-1与i这一段,或者dp[i-1][j][1]接上j与i这一段

  对于状态为1的时候,类似可以得到答案

  (思路来自KOKOZDRA的提交

  

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <iomanip>
  7.  
  8. using namespace std;
  9.  
  10. typedef long double ld;
  11.  
  12. const int M=2544;
  13.  
  14. struct node
  15. {
  16. int x,y;
  17. } p[M];
  18.  
  19. ld dis(node a,node b)
  20. {
  21. ld dx=a.x-b.x;
  22. ld dy=a.y-b.y;
  23. return sqrt(dx*dx+dy*dy);
  24. }
  25.  
  26. int n;
  27. ld mp[M][M];
  28. ld dp[M][M][2],ans; //dp[i][j][k] k==0 means i is ok to connect, otherwise j
  29.  
  30. void init()
  31. {
  32. int i,j,pi,qi;
  33. for(i=1;i<=n;i++)
  34. for(j=i;j<=n;j++)
  35. mp[i][j]=mp[j][i]=dis(p[i],p[j]);
  36. ans=0;
  37. }
  38.  
  39. int trf(int x)
  40. {
  41. if(x>n) return x-n;
  42. if(x<1) return x+n;
  43. return x;
  44. }
  45.  
  46. void solve()
  47. {
  48. memset(dp,0,sizeof(dp));
  49. int i,j,ti,tj;
  50. ld tmp;
  51. for(ti=2;ti<=n;ti++) //length
  52. for(tj=1;tj<=n;tj++)
  53. {
  54. i=tj; j=trf(tj+ti-1); //string of ([i~j] (if(j<i) j+=n))
  55. dp[i][j][0]=max(dp[trf(i+1)][j][0]+mp[trf(i+1)][i],dp[trf(i+1)][j][1]+mp[j][i]);
  56. dp[i][j][1]=max(dp[i][trf(j-1)][0]+mp[i][j],dp[i][trf(j-1)][1]+mp[trf(j-1)][j]);
  57. ans=max(ans,max(dp[i][j][0],dp[i][j][1]));
  58. }
  59. }
  60.  
  61. int main()
  62. {
  63. int i,j,it,qi,pi;
  64. ld tmp,mx;
  65. scanf("%d",&n);
  66. for(i=1;i<=n;i++)
  67. scanf("%d%d",&p[i].x,&p[i].y);
  68. init();
  69. solve();
  70. // printf("%.10Lf\n",ans);
  71. cout<<fixed<<setprecision(10)<<ans<<endl;
  72. return 0;
  73. }
  74.  
  75. /*
  76.  
  77. 7
  78. 0 0
  79. 0 1000
  80. 1 1000
  81. 1000 999
  82. 1001 1
  83. 1000 0
  84. 1 -1
  85.  
  86. */

  

  赛时真的贼痛苦、太菜

  

Codeforces 838E Convex Countour的更多相关文章

  1. Codeforces.838E.Convex Countour(区间DP)

    题目链接 \(Description\) 给定一个n边凸多边形(保证没有三点共线),求一条经过每个点最多一次的不会相交的路径,使得其长度最大.输出这个长度. \(Solution\) 最长路径应该是尽 ...

  2. 【CF838E】 Convex Countour

    [CF838E] Convex Countour 首先观察题目的性质 由于是凸包,因此不自交路径中的一条边\((x, y)\)的两端点只能向与\(x\)或\(y\)相邻的结点连边. 举个栗子,若选取了 ...

  3. codeforces B. Convex Shape 解题报告

    题目链接:http://codeforces.com/problemset/problem/275/B 题目内容:给出一个n * m 大小的grid,上面只有 black 和 white 两种颜色填充 ...

  4. Codeforces 101173 C - Convex Contour

    思路: 如果所有的图形都是三角形,那么答案是2*n+1 否则轮廓肯定触到了最上面,要使轮廓线最短,那么轮廓肯定是中间一段平的 我们考虑先将轮廓线赋为2*n+2,然后删去左右两边多余的部分 如果最左边或 ...

  5. Codeforces Round #270 1003

    Codeforces Round #270 1003 C. Design Tutorial: Make It Nondeterministic time limit per test 2 second ...

  6. codeforces 70D Professor's task(动态二维凸包)

    题目链接:http://codeforces.com/contest/70/problem/D Once a walrus professor Plato asked his programming ...

  7. Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学

    B. The Monster and the Squirrel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...

  8. Codeforces Round #270 A~D

    Codeforces Round #270 A. Design Tutorial: Learn from Math time limit per test 1 second memory limit ...

  9. Codeforces Round#413 Div.2

    A. Carrot Cakes 题面 In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, al ...

随机推荐

  1. Oracle-DQL 2- 限定和排序

    1.where子句--查询30号部门员工的姓名,职位和工资SELECT ename,job,sal,deptno FROM empWHERE deptno = 30; --查询职位是manager的员 ...

  2. 利用PLSQL Developer对oracle中的数据进行备份恢复

    --以备份scott用户为例,目标(备份里面所有的对象)--切换到scottconn scott/tiger;--进入  工具-->导出用户对象  如图所示 创建表空间及用户名,并赋予权限 -- ...

  3. python中while循环打印星星的四种形状

    在控制台连续输出五行*,每一行星号数量一次递增 * ** *** **** ***** #1.定义一个行计数器 row = 1 while row <= 5: #定义一个列计数器 col = 1 ...

  4. Linux磁盘挂载、分区、扩容操作

    本文最早发布于 Rootrl's blog 注:以下操作系统环境为CentOS7 基本概念 在操作前,首先要了解一些基本概念 磁盘 在Linux系统中所有的设备都会以文件的形式存储.设备一般保存在/d ...

  5. mysql 8.x 集群出现:Last_IO_Error: error connecting to master 'repl@xxx:3306' - retry-time: 60 retries: 1

    网上的经验:网络不同,账号密码不对,密码太长,密码由 # 字符:检查MASTER_HOST,MASTER_USER,MASTER_PASSWORD(不知道 MASTER_LOG_FILE 有没有影响) ...

  6. element-ui table float类型数据排序失败

    背景:对于16.88这样的数据,点击表头排序无效,仍然是乱序 解决办法:自定义排序方法,:sortable="true" :sort-mothod="xxxx" ...

  7. 服务端相关知识学习(五)之Zookeeper leader选举

    在上一篇文章中我们大致浏览了zookeeper的启动过程,并且提到在Zookeeper的启动过程中leader选举是非常重要而且最复杂的一个环节.那么什么是leader选举呢?zookeeper为什么 ...

  8. C++ const关键字以及static关键字

    const可以用来修饰类中的成员函数以及成员变量以及类的对象 1.const修饰成员函数: 该函数是只读函数,不允许修改任何成员变量,但是可以使用类中的任何成员变量: 不允许修改任何非static的类 ...

  9. SSE笔记

    1.8位加: *(__m128i*)(dest + i * 16) = _mm_add_epi8(*(__m128i*)(srcA + i * 16), *(__m128i*)(srcB + i * ...

  10. 4.图片左轮播图(swiper)

    一.html部分 二.js部分 三.源代码部分 <body> <div id="box"> <img src="imges/111.jpg& ...