最长上升子序列,枚举。

因为$10000$最多只有$10$个,所以可以枚举采用哪一个$10000$,因为是一个环,所以每次枚举到一个$10000$,可以把这个移到最后,然后算从前往后的$LIS$和从后往前的$LIS$,然后枚举一下哪里断开就可以了。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int a[],n;
  5. int b[],dp1[],dp2[];
  6. int c[],u,mx1[],mx2[];
  7.  
  8. void get(int L,int R,int l,int r,int rt)
  9. {
  10. if(L<=l&&r<=R)
  11. {
  12. u=max(u,c[rt]);
  13. return ;
  14. }
  15.  
  16. int m = (l+r)/;
  17. if(L<=m) get(L,R,l,m,*rt);
  18. if(R>m) get(L,R,m+,r,*rt+);
  19. }
  20.  
  21. void update(int pos,int val,int l,int r,int rt)
  22. {
  23. if(l==r)
  24. {
  25. c[rt] = val;
  26. return ;
  27. }
  28.  
  29. int m = (l+r)/;
  30. if(pos<=m) update(pos,val,l,m,*rt);
  31. if(pos>m) update(pos,val,m+,r,*rt+);
  32.  
  33. c[rt]=max(c[*rt],c[*rt+]);
  34. }
  35.  
  36. int main()
  37. {
  38. while(~scanf("%d",&n))
  39. {
  40. for(int i=;i<=n;i++) scanf("%d",&a[i]);
  41.  
  42. int ans=;
  43. for(int i=;i<=n;i++)
  44. {
  45. if(a[i]!=) continue;
  46.  
  47. for(int j=i+;j<=n;j++) b[j-i]=a[j];
  48. for(int j=;j<=i;j++) b[n-i+j]=a[j];
  49.  
  50. for(int j=;j<=n-;j++) if(b[j]==) b[j]=;
  51.  
  52. memset(dp1,,sizeof dp1);
  53. memset(dp2,,sizeof dp2);
  54.  
  55. memset(c,,sizeof c);
  56. for(int j=;j<=n-;j++)
  57. {
  58. u=; get(b[j],,,,);
  59. dp1[j] = u + b[j]; update(b[j],dp1[j],,,);
  60. }
  61.  
  62. memset(c,,sizeof c);
  63. for(int j=n-;j>=;j--)
  64. {
  65. u=; get(b[j],,,,);
  66. dp2[j] = u + b[j]; update(b[j],dp2[j],,,);
  67. }
  68.  
  69. for(int j=;j<=n-;j++) mx1[j]=max(mx1[j-],dp1[j]);
  70. for(int j=n-;j>=;j--) mx2[j]=max(mx2[j+],dp2[j]);
  71.  
  72. for(int j=;j<=n-;j++)
  73. {
  74. ans=max(ans,+dp1[j]);
  75. ans=max(ans,+dp2[j]);
  76. }
  77.  
  78. for(int j=;j<=n-;j++) ans=max(ans,+mx1[j]+mx2[j+]);
  79. }
  80.  
  81. printf("%d\n",ans);
  82. }
  83. return ;
  84. }

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. JAVA Thread Dumps 三部曲

    一.windows环境下方法 1:cmd下找到运行服务器容器的PID jps -v 例: C:\Users\Administrator>jps -v4856 Bootstrap -Djdk.tl ...

  2. select表单元素详解及下拉列表模拟实现

    原文地址:→看过来 写在前面 select 是HTML表单元素中很常用的一个,其中很重要的几个属性常被忽略,但这几个属性却能帮助我们完成很多的功能,当然,select下拉列表默认样式很不友好,所以更多 ...

  3. Assert 的用法

    Assert Assert是断言的意思,头文件为assert.h, assert是一个宏 功 能: 测试一个条件并可能使程序终止 用 法: void assert(int test); 在单元测试中经 ...

  4. Flex布局(伸缩盒布局)

    Flexible Box是什么?Flexible意为可伸缩的,Box意为盒子,可以理解为一种新式的盒模型——伸缩盒模型.由CSS3规范提出,这是在原有的大家非常熟悉的block, inline-blo ...

  5. 【BZOJ】1297: [SCOI2009]迷路

    [题意]给定n个点的有向带边权图,求0到n-1长度恰好为T的路径数.n<=10,T<=10^9,边权1<=wi<=9. [算法]矩阵快速幂 [题解]这道题的边权全部为1时,有简 ...

  6. 【BZOJ】2134: 单选错位 期望DP

    [题意]有n道题,第i道题有ai个选项.把第i道题的正确答案填到第i+1道题上(n填到1),问期望做对几道题.n<=10^7. [算法]期望DP [题解]正确答案的随机分布不受某道题填到后面是否 ...

  7. shell将多行文本重定向到文件【转】

    在shell中,使用Here Document方式将文本重定向到文件,格式如下: ( cat << EOF 要写的文本 EOF ) > 目标文件 示例test.sh: #! /bin ...

  8. linux删除第几天日志【原创】

    cat del.sh #!/bin/bash thirty=`date -d '30days ago' +%Y-%m-%d` cd $ #删除输入路径下第30天的日志文件 find . -name & ...

  9. python3.X和python2.7的区别

    1.python3.X将thread模块修改为_thread

  10. ACM——【百练习题备忘录】

    1. 在做百练2807题:两倍时,错将判断语句写成 a/b ==2,正确写法是:a == b*2 因为C/C++int型做除法时自动舍入,如:5/2 == 2,但是 5 =/= 2*2. 2. 在做百 ...