最长上升子序列,枚举。

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

  1. SCU - 4441 Necklace(树状数组求最长上升子数列)

    Necklace frog has \(n\) gems arranged in a cycle, whose beautifulness are \(a_1, a_2, \dots, a_n\). ...

  2. [scu 4423] Necklace

    4423: Necklace Description baihacker bought a necklace for his wife on their wedding anniversary. A ...

  3. SCOJ 4423: Necklace polya

    4423: Necklace 题目连接: http://acm.scu.edu.cn/soj/problem.action?id=4423 Description baihacker bought a ...

  4. HDU5730 Shell Necklace(DP + CDQ分治 + FFT)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5730 Description Perhaps the sea‘s definition of ...

  5. 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 ...

  6. ACM:SCU 4437 Carries - 水题

    SCU 4437  Carries Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice  ...

  7. ACM: SCU 4438 Censor - KMP

     SCU 4438 Censor Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice D ...

  8. ACM: SCU 4440 Rectangle - 暴力

     SCU 4440 Rectangle Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practic ...

  9. hdu 5727 Necklace dfs+二分图匹配

    Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...

随机推荐

  1. Ubuntu+NDK编译openssl

    为了Android上使用libcurl且支持HTTPS协议,需要依赖openssl,因此先来了解一下如何编译OpenSSL1.编译ARM下的共享库(默认的)我使用的是guardianproject的o ...

  2. springsecurity 表达式一览

    表达式 描述 hasRole([role]) 当前用户是否拥有指定角色. hasAnyRole([role1,role2]) 多个角色是一个以逗号进行分隔的字符串.如果当前用户拥有指定角色中的任意一个 ...

  3. GridControl详解(十)BandedGridView

    转换结果: 运行结果呈现:

  4. SMB MS17-010 利用(CVE-2017-0144 )

    exploit-db : https://www.exploit-db.com/exploits/42315/ 该漏洞的影响版本很广泛:Microsoft Windows Windows 7/8.1/ ...

  5. Dull Chocolates Gym - 101991D 离散化 前缀和

    题目链接:https://vjudge.net/problem/Gym-101991D 具体思路:首先看数据范围,暴力肯定不可以,可以下离散化,然后先求出离散化后每一个点到(1,1)的符合题目的要求的 ...

  6. koa通过get请求获取参数

    1.通过get方式请求获取参数的方式有两种 通过上下文获取 通过request获取 获得的格式有两种:query与querystring 注意:querystring为小写,驼峰格式会导致无法获取 2 ...

  7. JDK1.8新特性

    1.Lambda                                                            Lambda的语法目前仅对于只有一个抽象方法的接口. 在Lamb ...

  8. 37 - 网络编程-UDP编程

    目录 1 UDP协议 2 UDP通信流程 3 UDP编程 3.1 构建服务端 3.3 常用方法 4 聊天室 5 UDP协议应用 1 UDP协议 UDP是面向无连接的协议,使用UDP协议时,不需要建立连 ...

  9. SQL 变量 条件查询 插入数据

    (本文只是总结网络上的教程) 在操作数据库时 SQL语句中难免会用到变量 比如 在條件值已知的情況下 INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值 ...

  10. UVALive 3668 A Funny Stone Game

    题目链接:UVALive - 3668 题目大意为给定n堆石子,每次的操作是选择三个数i<j<=k,从i中拿一枚石子,在j和k中分别放入一枚石子.不能操作者输.求先手是否能赢,若可以,则输 ...