1421 - Wavio Sequence
题目大意:求一个序列中 先严格递增后严格递减的子序列的数目(要求这个子序列对称)。
题目思路:正一遍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的更多相关文章
- UVA 10534 三 Wavio Sequence
Wavio Sequence Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Sta ...
- 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 ...
- UVa 10534 Wavio Sequence (最长递增子序列 DP 二分)
Wavio Sequence Wavio is a sequence of integers. It has some interesting properties. · Wavio is of ...
- LIS UVA 10534 Wavio Sequence
题目传送门 题意:找对称的,形如:123454321 子序列的最长长度 分析:LIS的nlogn的做法,首先从前扫到尾,记录每个位置的最长上升子序列,从后扫到头同理.因为是对称的,所以取较小值*2-1 ...
- BNUOJ 14381 Wavio Sequence
Wavio Sequence Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Origina ...
- uva 10534 Wavio Sequence LIS
// uva 10534 Wavio Sequence // // 能够将题目转化为经典的LIS. // 从左往右LIS记作d[i],从右往左LIS记作p[i]; // 则最后当中的min(d[i], ...
- UVA10534:Wavio Sequence(最长递增和递减序列 n*logn)(LIS)好题
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=68553#problem/B 题目要求: Wavio是一个整数序列,具有以下特性 ...
- UVa10534 - Wavio Sequence(LIS)
题目大意 给定一个长度为n的整数序列,求个最长子序列(不一定连续),使得该序列的长度为奇数2k+1,前k+1个数严格递增,后k+1个数严格递减.注意,严格递增意味着该序列中的两个相邻数不能相同.n&l ...
- UVA 10534 Wavio Sequence
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=17&p ...
随机推荐
- Lucene的其他搜索(三)
生成索引: package com.wp.search; import java.nio.file.Paths; import org.apache.lucene.analysis.Analyzer; ...
- 原生js操作Dom命令总结
常用的dom方法 document.getElementById(“box”);//通过id获取标签 document.getElementsByTagName(“div”);根据标签名获取页面 ...
- Spring下redis的配置
这个项目用到redis,所以学了一下怎样在Spring框架下配置redis. 1.首先是在web.xml中添加Spring的配置文件. <web-app version="3.0&qu ...
- ps -ef | grep Linux进程查看命令
我们常常会想查看Linux的一些进程,很自然地用到了: ps -ef | grep xxx ps: process show 展示进程 参数:1. e 显示所有程序. 2. f 显示UID,PPIP ...
- Linux下常用的shell操作
# 设定hosts解析记录 sh-4.2# echo "$(ifconfig ens192 | awk '/\<inet\>/{print $2}') $(hostname)&q ...
- log4j、log4j2和slf4j的基本使用
一.什么是log4j.log4j2和slf4j Log4j是Apache的一个开源项目,通过配置来控制日志的输出.主要是控制日志的输出级别.输出位置和输出内容格式. Log4j2是在log4j框架的基 ...
- python 模块二(os,json,pickle)
#################################总结##################### os常用 os.makedirs('baby/安哥拉/特斯拉/黄晓明') os.mkd ...
- linux kill 命令【待完善】【转】
kill 命令用来处理进程, 在linux中即可使用kill -9 pid 杀死进程 , 也可使用kill -KILL pid 等价的命令来执行. HUP 1 终端断线 INT 2 中断(同 Ctrl ...
- windows cmd命令 批处理bat 导增量jar包【原】
下载地址 https://pan.baidu.com/s/1cIyCbG 导jar包 @echo off setlocal enabledelayedexpansion echo ---------- ...
- Part-One
首先,必须要声明一下,这个目录下的所有东西,是我对一本书复习,只是敲出部分代码让自己不至于眼高手低,其中有很多东西可能都是我的个人理解,如果有兴趣的朋友可以看一下,同时也欢迎大家指正. 1.Hello ...