最长上升子序列,枚举。

因为$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. OpenCV---开闭操作

    一:开操作(先腐蚀后膨胀) 特点:消除噪点,去除小的干扰块,而不影响原来的图像 import cv2 as cv import numpy as np def camp(val1,val2): pv ...

  2. 分享 koa + mysql 的开发流程,构建 node server端,一次搭建个人博客

    前言 由于一直在用 vue 写业务,为了熟悉下 react 开发模式,所以选择了 react.数据库一开始用的是 mongodb,后来换成 mysql 了,一套下来感觉 mysql 也挺好上手的.re ...

  3. 关于Linux运维的一些题目总结

    一.有文件file1 1.查询file1里面空行的所在行号 awk ‘{if($0~/^$/)print NR}’ fileorgrep -n ^$ file |awk ‘BEGIN{FS=”:”}{ ...

  4. 算法专题-STL篇

    这篇文章着重记录c++中STL的用法.主要粗略的介绍其用法,以知识点的形式呈现其功能,不会深入源码分析其工作原理. 排序和检索. sort(a,a+n),对a[0]往后的n个元素(包括a[0])进行排 ...

  5. 从零搭建SSM框架(五)Maven实现Tomcat热部署

    配置tomcat 第一步:需要修改tomcat的conf/tomcat-users.xml配置文件.添加用户名.密码.权限. <role rolename="manager-gui&q ...

  6. 【BZOJ】2599: [IOI2011]Race 点分治

    [题意]给一棵树,每条边有权.求一条简单路径,权值和等于K,且边的数量最小.N <= 200000, K <= 1000000.注意点从0开始编号,无解输出-1. [算法]点分治 [题解] ...

  7. 20155117王震宇 实验一《Java开发环境的熟悉》实验报告

    (一)使用JDK编译.运行简单的java程序 命令创建实验目录 输入mkdir 2051117 创建以自己学号命名的文件夹,通过cd命令移动到指定文件夹,输入mkdir exp1创建实验文件夹. 打开 ...

  8. 快速幂取模_C++

    一.题目背景 已知底数a,指数b,取模值mo 求ans = ab % mo 二.朴素算法(已知可跳过) ans = 1,循环从 i 到 b ,每次将 ans = ans * a % mo 时间复杂度O ...

  9. 简单响应式Bootstrap框架中文官网页面模板

    链接:http://pan.baidu.com/s/1o7MQ6RC 密码:kee5

  10. 导航狗IT周报-2018年05月27日

    原文链接:https://www.daohanggou.cn/2018/05/27/it-weekly-9/ 摘要: “灰袍技能圈子”将闭圈:物理安全:为什么我们现在的生活节奏越来越快? 技术干货 1 ...