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的更多相关文章

  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. python 下安装pymysql应用

    前言 pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持3.x版本. 本文测试python版本:2.7.11. ...

  2. spring boot 使用elasticsearch

    在文章开始之前我们先来介绍一下elasticsearch 是一个分布式的 RESTful 风格的搜索和数据分析引擎. 查询 : Elasticsearch 允许执行和合并多种类型的搜索 — 结构化.非 ...

  3. [git] git error: unable to unlink old

    今天git pull ,结果报错 :   git error: unable to unlink old 原因是   文件夹内 一个exe 处于打开状态. 哈哈哈哈,又是个低级错误~~~ 下次注意呀~

  4. 第2章:Python生态工具

    1.Python内置小工具 1).1秒钟启动一个下载服务器: python -m SimpleHTTPServer python3 -m http.server 会在当前目录下启动一个文件下载服务器, ...

  5. Java EE javax.servlet中的Servlet接口

    Servlet接口 public interface Servlet 其实现类有:FaceServlet.GenericServlet.HttpServlet 一.介绍 Servlet接口定义了所有s ...

  6. 使用kafka-eagle监控Kafka

    # 监控kafka集群,开启监控趋势图使用 # 有一个问题,需要在kafka-server-start.sh文件中配置端口,有如下三种办法 # 第一种:复制并修改kafka目录,比如kafka-1,k ...

  7. javascript——定义函数方式

    1:有名函数定义方式 2:匿名函数定义方法 https://www.cnblogs.com/wl0000-03/p/6050108.html console.log(add(3,6)); (funct ...

  8. 小白学 Python 爬虫(25):爬取股票信息

    人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...

  9. 带她来看Frozen 2

  10. 利用宏方便地书写raw string literals

    以前一直没用过标准库的regex,今天写一个hlsl的解析工具的时候用了一下,发现用字符串字面值写regular expression的时候非常不方便,特别是每个“\”字符都要被识别为转义,只能写成“ ...