题目大意:求一个序列中 先严格递增后严格递减的子序列的数目(要求这个子序列对称)。

题目思路:正一遍DP,反一遍DP,因为n<=1e5,dp要把时间压缩到nlogn

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define MAXSIZE 100005 using namespace std; int dp[MAXSIZE],a[MAXSIZE]; int n; int Solve()
{
dp[] = ;
int G1[MAXSIZE],G2[MAXSIZE],len=,pos;
G1[] = a[];
for(int i=;i<=n;i++)
{
if(a[i] > G1[len])
pos = ++len;
else
{
pos = lower_bound(G1+,G1++len,a[i]) - (G1+) + ;
}
G1[pos] = a[i];
dp[i] = len;
} G2[] = a[n];
len = ;
int ans = ;
for(int i=n-;i>=;i--)
{
if(a[i] > G2[len])
pos = ++len;
else
pos = lower_bound(G2+,G2++len,a[i]) - (G2+) + ;
G2[pos] = a[i];
int temp = min(len,dp[i]);
ans = max(ans,temp);
}
return *ans - ;
} int main()
{
int T,cns=;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int ans =Solve();
printf("Case %d: %d\n",cns++,ans);
}
return ;
}

1421 - Wavio Sequence的更多相关文章

  1. UVA 10534 三 Wavio Sequence

    Wavio Sequence Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Sta ...

  2. HOJ 2985 Wavio Sequence(最长递增子序列以及其O(n*logn)算法)

    Wavio Sequence My Tags (Edit) Source : UVA Time limit : 1 sec Memory limit : 32 M Submitted : 296, A ...

  3. UVa 10534 Wavio Sequence (最长递增子序列 DP 二分)

    Wavio Sequence  Wavio is a sequence of integers. It has some interesting properties. ·  Wavio is of ...

  4. LIS UVA 10534 Wavio Sequence

    题目传送门 题意:找对称的,形如:123454321 子序列的最长长度 分析:LIS的nlogn的做法,首先从前扫到尾,记录每个位置的最长上升子序列,从后扫到头同理.因为是对称的,所以取较小值*2-1 ...

  5. BNUOJ 14381 Wavio Sequence

    Wavio Sequence Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Origina ...

  6. uva 10534 Wavio Sequence LIS

    // uva 10534 Wavio Sequence // // 能够将题目转化为经典的LIS. // 从左往右LIS记作d[i],从右往左LIS记作p[i]; // 则最后当中的min(d[i], ...

  7. UVA10534:Wavio Sequence(最长递增和递减序列 n*logn)(LIS)好题

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=68553#problem/B 题目要求: Wavio是一个整数序列,具有以下特性 ...

  8. UVa10534 - Wavio Sequence(LIS)

    题目大意 给定一个长度为n的整数序列,求个最长子序列(不一定连续),使得该序列的长度为奇数2k+1,前k+1个数严格递增,后k+1个数严格递减.注意,严格递增意味着该序列中的两个相邻数不能相同.n&l ...

  9. UVA 10534 Wavio Sequence

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=17&p ...

随机推荐

  1. Unity 着色过程

    图形API包括:OpenGL.Metal.Vulkan.Director3D. 渲染管线(图形管线)通用结构: 1.数据收集(图形的网格.纹理.材质)--------2.顶点着色器(获取图形的2D坐标 ...

  2. HDU3974 Assign the task

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. 使用docker-compose部署nginx

      1.新建docker-compose.yml文件,文件的基本模板如下:(由于yml格式比较严格,注意空格缩进) version: '2.0' services: nginx: restart: a ...

  4. icmpsh解决运行报错

    运行./run.sh报错 sysctl -w net.ipv4.icmp_echo_ignore_all=1 >/dev/null python icmpsh_m.py 攻击机ip 目标机ip ...

  5. 2017-12-18python全栈9期第三天第四节之str的索引与切片

    #!/user/bin/python# -*- coding:utf-8 -*-s = 'zdlswwzl's1 = s[0]print(s1)s2 = s[-1]print(s2)s3 = s[0: ...

  6. i2c框架

    目录 i2c框架 寄存器 主机发送 主机接收 中断处理 程序框架 title: iic框架 tags: ARM date: 2018-11-05 13:44:58 --- i2c框架 寄存器 /* 配 ...

  7. vue基础篇---路由的实现《2》

    现在我们来实现这样一个功能: 一个页面,包含登录和注册,点击不同按钮,实现登录和注册页切换: 编写父组件 index.html <div id="app"> <s ...

  8. Hbase记录-shell脚本嵌入hbase shell命令

    第一种方式:hbase shell test.txt test.txt:list 第二种方式:<<EOF重定向输入 我们经常在shell脚本程序中用<<EOF重定向输入,将我们 ...

  9. ssh框架里拦截器的权限验证基本思路【转】

    相关表 序号 表性质 表名 字段 字段 字段 字段 字段 1 基表 用户表 id 帐号 密码     2 基表 角色表 id 角色名       3 基表 权限表 id 权限名 请求路径     4 ...

  10. 分享12款 JavaScript 表格控件(DataGrid)

    JavaScript 表格控件可以操作大数据集的 HTML 表格,提供各种功能,如分页.排序.过滤以及行编辑.在本文中,我们整理了13个最好的 JavaScript 表格插件分享给开发人员,开发者可以 ...