Codeforces 838E Convex Countour
题
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的提交)
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- #include <cmath>
- #include <algorithm>
- #include <iomanip>
- using namespace std;
- typedef long double ld;
- const int M=2544;
- struct node
- {
- int x,y;
- } p[M];
- ld dis(node a,node b)
- {
- ld dx=a.x-b.x;
- ld dy=a.y-b.y;
- return sqrt(dx*dx+dy*dy);
- }
- int n;
- ld mp[M][M];
- ld dp[M][M][2],ans; //dp[i][j][k] k==0 means i is ok to connect, otherwise j
- void init()
- {
- int i,j,pi,qi;
- for(i=1;i<=n;i++)
- for(j=i;j<=n;j++)
- mp[i][j]=mp[j][i]=dis(p[i],p[j]);
- ans=0;
- }
- int trf(int x)
- {
- if(x>n) return x-n;
- if(x<1) return x+n;
- return x;
- }
- void solve()
- {
- memset(dp,0,sizeof(dp));
- int i,j,ti,tj;
- ld tmp;
- for(ti=2;ti<=n;ti++) //length
- for(tj=1;tj<=n;tj++)
- {
- i=tj; j=trf(tj+ti-1); //string of ([i~j] (if(j<i) j+=n))
- 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]);
- 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]);
- ans=max(ans,max(dp[i][j][0],dp[i][j][1]));
- }
- }
- int main()
- {
- int i,j,it,qi,pi;
- ld tmp,mx;
- scanf("%d",&n);
- for(i=1;i<=n;i++)
- scanf("%d%d",&p[i].x,&p[i].y);
- init();
- solve();
- // printf("%.10Lf\n",ans);
- cout<<fixed<<setprecision(10)<<ans<<endl;
- return 0;
- }
- /*
- 7
- 0 0
- 0 1000
- 1 1000
- 1000 999
- 1001 1
- 1000 0
- 1 -1
- */
赛时真的贼痛苦、太菜
Codeforces 838E Convex Countour的更多相关文章
- Codeforces.838E.Convex Countour(区间DP)
题目链接 \(Description\) 给定一个n边凸多边形(保证没有三点共线),求一条经过每个点最多一次的不会相交的路径,使得其长度最大.输出这个长度. \(Solution\) 最长路径应该是尽 ...
- 【CF838E】 Convex Countour
[CF838E] Convex Countour 首先观察题目的性质 由于是凸包,因此不自交路径中的一条边\((x, y)\)的两端点只能向与\(x\)或\(y\)相邻的结点连边. 举个栗子,若选取了 ...
- codeforces B. Convex Shape 解题报告
题目链接:http://codeforces.com/problemset/problem/275/B 题目内容:给出一个n * m 大小的grid,上面只有 black 和 white 两种颜色填充 ...
- Codeforces 101173 C - Convex Contour
思路: 如果所有的图形都是三角形,那么答案是2*n+1 否则轮廓肯定触到了最上面,要使轮廓线最短,那么轮廓肯定是中间一段平的 我们考虑先将轮廓线赋为2*n+2,然后删去左右两边多余的部分 如果最左边或 ...
- Codeforces Round #270 1003
Codeforces Round #270 1003 C. Design Tutorial: Make It Nondeterministic time limit per test 2 second ...
- codeforces 70D Professor's task(动态二维凸包)
题目链接:http://codeforces.com/contest/70/problem/D Once a walrus professor Plato asked his programming ...
- 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 ...
- Codeforces Round #270 A~D
Codeforces Round #270 A. Design Tutorial: Learn from Math time limit per test 1 second memory limit ...
- 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 ...
随机推荐
- Oracle-DQL 2- 限定和排序
1.where子句--查询30号部门员工的姓名,职位和工资SELECT ename,job,sal,deptno FROM empWHERE deptno = 30; --查询职位是manager的员 ...
- 利用PLSQL Developer对oracle中的数据进行备份恢复
--以备份scott用户为例,目标(备份里面所有的对象)--切换到scottconn scott/tiger;--进入 工具-->导出用户对象 如图所示 创建表空间及用户名,并赋予权限 -- ...
- python中while循环打印星星的四种形状
在控制台连续输出五行*,每一行星号数量一次递增 * ** *** **** ***** #1.定义一个行计数器 row = 1 while row <= 5: #定义一个列计数器 col = 1 ...
- Linux磁盘挂载、分区、扩容操作
本文最早发布于 Rootrl's blog 注:以下操作系统环境为CentOS7 基本概念 在操作前,首先要了解一些基本概念 磁盘 在Linux系统中所有的设备都会以文件的形式存储.设备一般保存在/d ...
- 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 有没有影响) ...
- element-ui table float类型数据排序失败
背景:对于16.88这样的数据,点击表头排序无效,仍然是乱序 解决办法:自定义排序方法,:sortable="true" :sort-mothod="xxxx" ...
- 服务端相关知识学习(五)之Zookeeper leader选举
在上一篇文章中我们大致浏览了zookeeper的启动过程,并且提到在Zookeeper的启动过程中leader选举是非常重要而且最复杂的一个环节.那么什么是leader选举呢?zookeeper为什么 ...
- C++ const关键字以及static关键字
const可以用来修饰类中的成员函数以及成员变量以及类的对象 1.const修饰成员函数: 该函数是只读函数,不允许修改任何成员变量,但是可以使用类中的任何成员变量: 不允许修改任何非static的类 ...
- SSE笔记
1.8位加: *(__m128i*)(dest + i * 16) = _mm_add_epi8(*(__m128i*)(srcA + i * 16), *(__m128i*)(srcB + i * ...
- 4.图片左轮播图(swiper)
一.html部分 二.js部分 三.源代码部分 <body> <div id="box"> <img src="imges/111.jpg& ...