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. Redis(1.14)Redis日常管理与维护

    [1]持久化 如果不做持久化,用replication去保证可用性,另外最后可以通过引用从数据库同步最新数据. 因此注释掉所有的持久化策略,添加一条带空字符串参数的save指令,也能移除之前所有配置的 ...

  2. selenium开发-C#/java/Python

    背景:之前由于自己有编写CefSharp.WinForms 窗体版以及 接口化 WCF+CefSharp.WinForms的网站版本,但是由于某些原因,延伸出Selenium学习与研究 总结:sele ...

  3. plsql软件使用手册

    记录登陆密码及用户名

  4. sqarkSQL hiveSql

    查看数据库 show databases; 进入数据库 use 库名 查看表 show tables: select * from 表名 hdfs传输spark sql查询 hive找到指定路径sql ...

  5. 第9章:LeetCode--算法:HASH表

    哈希表(Hash table,也叫散列表),关键值K和内容的映射表,通过映射函数实现,hashtable(key,value) 进行查询的时候,就是使用哈希函数将关键码key转换为对应的数组下标,并定 ...

  6. 减2或减3(很搞的贪心)2019牛客国庆集训派对day6

    题意:https://ac.nowcoder.com/acm/contest/1111/D 问你先减二x次的情况下,最少减几次3. 思路: %3不为0的要先减2,然后%3为0的要先减大的(比如9 3 ...

  7. 接口踩坑:Status (blocked:other)

    1.请求接口时出现 Status (blocked:other) 2.原因分析:安装了Adblock 3.解决办法 1)关掉Adblock2)修改接口名称,不能用 ad 或者 XX ad XX 等名称 ...

  8. python + Pyglet ---播放视频

    记得安装pyglet 包,AVbin(http://avbin.github.io/AVbin/Download.html) 参考链接: Pyglet教程 http://www.hawstein.co ...

  9. hive用户自定义函数

    一.UDF 1.显示所有函数:show functions ; 2.显示指定函数的帮助:$hive>desc function current_database(); 3. 什么是 UDF? 当 ...

  10. left join 和 inner join 区别和优化

    关联查询总结,left join 和 inner join 区别和优化 一直以来都没有细细的研究 left join 和 inner join,现在发觉要做优化还真的是要熟悉它们的区别才行. 原谅转载 ...