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 ...
随机推荐
- 介绍 JSON (转)
本文转自:http://www.json.org/json-zh.html JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于 ...
- bzoj 3884 欧拉定理
求$$2^{2^{2^{2^{…}}}} mod n$$的值,其中n有1e7. 老实说这题挺有趣的,关键是怎么化掉指数,由于是取模意义下的无限个指数,所以使用欧拉定理一定是可以把指数变为不大于$\va ...
- 笔记(二)TabLayout + ViewPager + FragmentPagerAdapter 组合用法
TabLayout的xml文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...
- MySQL主键和索引的联系及区别
转载自:http://www.nowamagic.net/librarys/veda/detail/1954 关系数据库依赖于主键,它是数据库物理模式的基石.主键在物理层面上只有两个用途: 惟一地标识 ...
- 接口自动化测试框架HttpRunner
接口自动化测试框架 https://github.com/HttpRunner/HttpRunner http://debugtalk.com/post/ApiTestEngine-api-test- ...
- 23、Xpath
1.什么是Xpath?1.XPath即为XMLPath的简称,它是一种用来确定XML文档中某部分位置的语言.2.HTML可以看做是XML的一种实现,所以selenium用户可以使用这种强大的语言在we ...
- python开发规范(转载)
转载自http://www.cnblogs.com/wangcp-2014/p/4838952.html 目录 代码布局 1.1 缩进 1.2 表达式和语句中的空格 1.3 行的最大长度 1.4 空行 ...
- 70.如何在xilinx SDK中显示行号
Window→preferences→editor→test editor 对ecilpse的通用方法 打开Eclipse软件,在菜单中选择窗口——首选项,打开新的窗口. 在新的窗口中依次选择常规—— ...
- Mutex, semaphore, spinlock的深度解析
Mutex是一把钥匙,一个人拿了就可进入一个房间,出来的时候把钥匙交给队列的第一个.一般的用法是用于串行化对critical section代码的访问,保证这段代码不会被并行的运行. Semaphor ...
- Java network programming-guessing game
猜数字游戏 游戏的规则如下: 当客户端第一次连接到服务器端时,服务器端生产一个[0,50]之间的随机数字,然后客户端输入数字来猜该数字,每次客户端输入数字以后,发送给服务器端,服务器端判断该客户端发送 ...