最长上升子序列,枚举。

因为$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. 子集系列(二) 满足特定要求的子集,例 [LeetCode] Combination, Combination Sum I, II

    引言 既上一篇 子集系列(一) 后,这里我们接着讨论带有附加条件的子集求解方法. 这类题目也是求子集,只不过不是返回所有的自己,而往往是要求返回满足一定要求的子集. 解这种类型的题目,其思路可以在上一 ...

  2. MySQL免安装版配置部署

    MySQL下载地址:http://dev.mysql.com/downloads/mysql/ 1.Windows下安装MySQL 我下的是最新版的MySQL,解压后,目录如下: 将解压目录下默认文件 ...

  3. UVA 1575 Factors

    https://vjudge.net/problem/UVA-1575 题意: 令f(k)=n 表示 有n种方式,可以把正整数k表示成几个数的乘积的形式. 例 10=2*5=5*2,所以f(10)=2 ...

  4. 每个Web开发者都需要具备的9个软技能

    对于一份工作,你可能专注于修炼自己的内功,会在不自觉中忽视软技能.硬技能决定你是否能得到工作,而软技能能够表明你是否适合这份工作和适应工作环境等.所有的公司都有属于自己的文化,并努力将这些文化传承下去 ...

  5. CodeForces 869B

    Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...

  6. CF 900B

    CF 900B Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Descript ...

  7. 【洛谷 P4219】 [BJOI2014]大融合(LCT)

    题目链接 维护子树信息向来不是\(LCT\)所擅长的,所以我没搞懂qwq 权当背背模板吧.Flash巨佬的blog里面写了虽然我没看懂. #include <cstdio> #define ...

  8. kali2.0安装虚拟机工具

    kali2.0无法安装虚拟机工具,显示VMware Tools无法用于该虚拟机,或者安装之后无法进行复制.粘贴等操作. 解决办法: step1: 更换源 root@starnight:~# vim / ...

  9. Redis数据类型之字符串(string)

    1. string类型简介 string类型是二进制安全的,能够存储任意类型的字符串. string类型是最常用到的数据类型,一种常用的用法就是将对象格式化为JSON字符串然后放到redis中,取出来 ...

  10. Jsoup爬取带登录验证码的网站

    今天学完爬虫之后想的爬一下我们学校的教务系统,可是发现登录的时候有验证码.因此研究了Jsoup爬取带验证码的网站: 大体的思路是:(需要注意的是__VIEWSTATE一直变化,所以我们每个页面都需要重 ...