SCU 4441 Necklace
最长上升子序列,枚举。
因为$10000$最多只有$10$个,所以可以枚举采用哪一个$10000$,因为是一个环,所以每次枚举到一个$10000$,可以把这个移到最后,然后算从前往后的$LIS$和从后往前的$LIS$,然后枚举一下哪里断开就可以了。
#include<bits/stdc++.h>
using namespace std; int a[],n;
int b[],dp1[],dp2[];
int c[],u,mx1[],mx2[]; void get(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
u=max(u,c[rt]);
return ;
} int m = (l+r)/;
if(L<=m) get(L,R,l,m,*rt);
if(R>m) get(L,R,m+,r,*rt+);
} void update(int pos,int val,int l,int r,int rt)
{
if(l==r)
{
c[rt] = val;
return ;
} int m = (l+r)/;
if(pos<=m) update(pos,val,l,m,*rt);
if(pos>m) update(pos,val,m+,r,*rt+); c[rt]=max(c[*rt],c[*rt+]);
} int main()
{
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++) scanf("%d",&a[i]); int ans=;
for(int i=;i<=n;i++)
{
if(a[i]!=) continue; for(int j=i+;j<=n;j++) b[j-i]=a[j];
for(int j=;j<=i;j++) b[n-i+j]=a[j]; for(int j=;j<=n-;j++) if(b[j]==) b[j]=; memset(dp1,,sizeof dp1);
memset(dp2,,sizeof dp2); memset(c,,sizeof c);
for(int j=;j<=n-;j++)
{
u=; get(b[j],,,,);
dp1[j] = u + b[j]; update(b[j],dp1[j],,,);
} memset(c,,sizeof c);
for(int j=n-;j>=;j--)
{
u=; get(b[j],,,,);
dp2[j] = u + b[j]; update(b[j],dp2[j],,,);
} for(int j=;j<=n-;j++) mx1[j]=max(mx1[j-],dp1[j]);
for(int j=n-;j>=;j--) mx2[j]=max(mx2[j+],dp2[j]); for(int j=;j<=n-;j++)
{
ans=max(ans,+dp1[j]);
ans=max(ans,+dp2[j]);
} for(int j=;j<=n-;j++) ans=max(ans,+mx1[j]+mx2[j+]);
} printf("%d\n",ans);
}
return ;
}
SCU 4441 Necklace的更多相关文章
- SCU - 4441 Necklace(树状数组求最长上升子数列)
Necklace frog has \(n\) gems arranged in a cycle, whose beautifulness are \(a_1, a_2, \dots, a_n\). ...
- [scu 4423] Necklace
4423: Necklace Description baihacker bought a necklace for his wife on their wedding anniversary. A ...
- SCOJ 4423: Necklace polya
4423: Necklace 题目连接: http://acm.scu.edu.cn/soj/problem.action?id=4423 Description baihacker bought a ...
- HDU5730 Shell Necklace(DP + CDQ分治 + FFT)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5730 Description Perhaps the sea‘s definition of ...
- 2016 Multi-University Training Contest 1 H.Shell Necklace
Shell Necklace Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- ACM:SCU 4437 Carries - 水题
SCU 4437 Carries Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice ...
- ACM: SCU 4438 Censor - KMP
SCU 4438 Censor Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practice D ...
- ACM: SCU 4440 Rectangle - 暴力
SCU 4440 Rectangle Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu Practic ...
- hdu 5727 Necklace dfs+二分图匹配
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...
随机推荐
- 0UE3 材质概要
材质概要 概述 参数 当创建材质时如何考虑颜色 材质表达式 Abs(求绝对值) 添加 AntialiasedTextureMask AppendVector(向量合并) BumpOffset(凸凹偏移 ...
- Python学习笔记(四十)— 内置模块(9)HTMLParser
摘抄自:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432002312 ...
- Spring Boot 使用IntelliJ IDEA创建一个web开发实例(三)
属性配置 1.配置application.properties文件 配置web访问端口和context path server.port = 8081 server.servlet.context-p ...
- 读书笔记 ~ Nmap渗透测试指南
记录Nmap选项及脚本使用,仅供参考... 除了端口扫描,好像其它脚本都比较鸡肋,用途感觉应该没有专用的小工具好用,不过还是可以看看,选项和脚本还是相当的丰富的. Nmap 使用帮助 starnigh ...
- Django(基础篇)
1.请求周期 url> 路由 > 函数或类 > 返回字符串或者模板语言? Form表单提交: 提交 -> url > 函数或类中的方法 ...
- struts的标签
<%@ taglib uri="/struts-tags" prefix="s"%> <%@ taglib uri="/WEB-IN ...
- C# Selenium with PhantomJSDriver get image width and height (获取图片的长和高)
//get image width and height var image=driver.FindElement(By.ClassName("it-Header_authorImage&q ...
- 设计模式之笔记--代理模式(Proxy)
代理模式(Proxy) 定义 代理模式(Proxy),为其他对象提供一种代理以控制对这个对象的访问. 类图 描述 Subject,定义了ConcreteSubject和Proxy的共用接口,这样就可以 ...
- [ python ] 接口类和抽象类
接口类 继承有两种用途:1. 继承基类的方法,并且做出自己的改变或者扩展(代码重用)2. 申明某个子类兼容于某基类,定义一个接口类interface,接口类定义了一些接口名且未实现接口的功能,子类继承 ...
- 51Nod 1352 集合计数(扩展欧几里德)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1352 题目大意: 给出N个固定集合{1,N},{2,N-1} ...