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 ...
随机推荐
- 初学K3Cloud开发
1.BOS中在新建的空白对象中添加一个下推按钮 1.点击“菜单集合”属性 2.在打开的窗体中,点中“工具条”,新增一个按钮 3.将新增的按钮标题改为“下推”,并配置点击事件 列表菜单增加“下推”类似, ...
- Photon Server初识(二) ---通过NHibernate 映射数据库
一.下载 NHibernate.dill 官网:https://nhibernate.info 或者通过NuGet下载(详情看上一节) 二.新建一个项目,并引入包 引入包 三.配置(重点) 1.配置x ...
- Elastic Search中normalization和分词器
为key_words提供更加完整的倒排索引. 如:时态转化(like | liked),单复数转化(man | men),全写简写(china | cn),同义词(small | little)等. ...
- 并不对劲的bzoj4231: 回忆树
题目大意 \(n\)个点的树,每条边上有一个小写字母. 操作:给定2个点\(u\),\(v\)(\(u\)可能等于\(v\))和一个非空字符串\(s\),问从\(u\)到\(v\)的简单路径上的所有边 ...
- C#面向对象20 序列化和反序列化
序列化和反序列化 序列化是把一个内存中的对象的信息转化成一个可以持久化保存的形式,以便于保存或传输,序列化的主要作用是不同平台之间进行通信,常用的有序列化有json.xml.文件等 一.序列化为j ...
- 【原创】大叔经验分享(62)kudu副本数量
kudu的副本数量是在表上设置,可以通过命令查看 # sudo -u kudu kudu cluster ksck $master ... Summary by table Name | RF | S ...
- O031、Start Instance 操作详解
参考https://www.cnblogs.com/CloudMan6/p/5470723.html 本节将通过日志文件分析 instance start 的操作过程,下面是 start inst ...
- LeetCode:175.组合两个表
题目链接:https://leetcode-cn.com/problems/combine-two-tables/ 题目 表1: Person +-------------+---------+ | ...
- vue中修改数组,dom未更新的问题
vue中我们会频繁操作各种数据,但有时候发现修改完数据以后,dom并未更新? 比如有一个数组对象: obj = [{'name': 'joy'},{'name': 'bowen'}] 我要循坏插入某个 ...
- jeesite直接登录——真实破解
前台 后台 @RequiresPermissions("alarm:alarm:view")一定要注释 —————————————————————————————————————— ...