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 ...
随机推荐
- LKM rootkit:Reptile学习
简介 Reptile是github上一个很火的linux lkm rootkit,最近学习了一些linux rootkit的内容,在这里记录一下. 主要是分析reptile的实现 Reptile的使用 ...
- Centos7 系统启动docker报错 inotify add watch failed
环境说明: 最近新装的系统启动docker报错,之前没有遇到过.(之前都是系统直接启动,新装机器无报错的情况) 当时排查了很久没找到问题在哪,观察报错信息如下: 提示表文件失败,没有这个文件或者目录. ...
- Js 参数乱码
在前台,对URL的中文参数执行两次encodeURI: 序列化 var param = encodeURI(encodeURI("中文")); 反序列化 decodeURI($. ...
- O043、计算节点宕机了怎么办
参考https://www.cnblogs.com/CloudMan6/p/5562131.html Rebuild 可以恢复损坏的instance .那如果是宿主机坏了怎么办呢?比如硬件故障或者 ...
- mysq练习
表名和字段 –1.学生表Student(s_id,s_name,s_birth,s_sex) --学生编号,学生姓名, 出生年月,学生性别–2.课程表Course(c_id,c_name,t_id) ...
- 转:GitHub团队项目合作流程
转自:https://www.cnblogs.com/schaepher/p/4933873.html GitHub团队项目合作流程 已在另一篇博客中写出关于以下问题的解决,点此进入: 同步团队项 ...
- Base64加密后有换行回车的解决办法
据RFC 822规定,每76个字符,还需要加上一个回车换行 有时就因为这些换行弄得出了问题,解决办法如下,替换所有换行和回车 String bTemp = Base64.encodeBase64Str ...
- fetch的文件流下载及下载进度获取
下载过程中,获取进度,fetch API并没有提供类似xhr和ajax的 progress所以用 getReader()来循环读取大小 let size = 0; fetch( URL() + `/s ...
- EF 将MSSQL 更换成 POSTRESQL
前提概要:项目里已存在MSSQL 的 DB FIRST 的EDMX, 想将项目的数据库转换成 POSTGRESQL. 解决方法: 1,新建项目, 连接MSSQL 建立模型,用来源于数据库 CODE F ...
- 第十章· Logstash深入-Logstash与Redis那点事
Logstash将日志写入Redis 为什么要使用Redis 在企业中,日志规模的量级远远超出我们的想象,这就是为什么会有一家公司日志易专门做日志收集,给大型金融公司收集日志,比如银行,因为你有可能看 ...