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 ...
随机推荐
- JAVA Thread Dumps 三部曲
一.windows环境下方法 1:cmd下找到运行服务器容器的PID jps -v 例: C:\Users\Administrator>jps -v4856 Bootstrap -Djdk.tl ...
- select表单元素详解及下拉列表模拟实现
原文地址:→看过来 写在前面 select 是HTML表单元素中很常用的一个,其中很重要的几个属性常被忽略,但这几个属性却能帮助我们完成很多的功能,当然,select下拉列表默认样式很不友好,所以更多 ...
- Assert 的用法
Assert Assert是断言的意思,头文件为assert.h, assert是一个宏 功 能: 测试一个条件并可能使程序终止 用 法: void assert(int test); 在单元测试中经 ...
- Flex布局(伸缩盒布局)
Flexible Box是什么?Flexible意为可伸缩的,Box意为盒子,可以理解为一种新式的盒模型——伸缩盒模型.由CSS3规范提出,这是在原有的大家非常熟悉的block, inline-blo ...
- 【BZOJ】1297: [SCOI2009]迷路
[题意]给定n个点的有向带边权图,求0到n-1长度恰好为T的路径数.n<=10,T<=10^9,边权1<=wi<=9. [算法]矩阵快速幂 [题解]这道题的边权全部为1时,有简 ...
- 【BZOJ】2134: 单选错位 期望DP
[题意]有n道题,第i道题有ai个选项.把第i道题的正确答案填到第i+1道题上(n填到1),问期望做对几道题.n<=10^7. [算法]期望DP [题解]正确答案的随机分布不受某道题填到后面是否 ...
- shell将多行文本重定向到文件【转】
在shell中,使用Here Document方式将文本重定向到文件,格式如下: ( cat << EOF 要写的文本 EOF ) > 目标文件 示例test.sh: #! /bin ...
- linux删除第几天日志【原创】
cat del.sh #!/bin/bash thirty=`date -d '30days ago' +%Y-%m-%d` cd $ #删除输入路径下第30天的日志文件 find . -name & ...
- python3.X和python2.7的区别
1.python3.X将thread模块修改为_thread
- ACM——【百练习题备忘录】
1. 在做百练2807题:两倍时,错将判断语句写成 a/b ==2,正确写法是:a == b*2 因为C/C++int型做除法时自动舍入,如:5/2 == 2,但是 5 =/= 2*2. 2. 在做百 ...