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 ...
随机推荐
- Deepin或者Ubuntu上永久配件navicat
1.深度商店下载安装Navicat,期间可能会要求安装wine等. 2.安装完毕 终端环境下找到Navicat的安装目录 langzi@langzi-PC:~$ whereis ...
- 爬虫之requests请求库
介绍 #介绍:使用requests可以模拟浏览器的请求,比起之前用到的urllib,requests模块的api更加便捷(本质就是封装了urllib3) #注意:requests库发送请求将网页内容下 ...
- makefile解析:一些常用函数
#======================================================================= #指定目标文件名,makefile中的变量直接使用不用 ...
- 7、JPA-映射-双向一对多
一个用户对应多个订单,多个订单对应一个用户,不管查哪一边都可以得到另一边的信息 实体类 Customer package com.jpa.yingshe; import javax.persisten ...
- centos6.5mini版安装及配置
1.安装选择界面,这个选第一个 2.镜像完整性检查,一般都是跳过SKIP 3.欢迎界面,进入安装了 4.语言选择,这个是没有中文的,用默认的英文就行 5.键盘布局,用默认的us 6.这里会给一个警告, ...
- Timus 1132 Square Root(二次剩余)
http://acm.timus.ru/problem.aspx?space=1&num=1132 题意: 求 x^2 ≡ n mod p p是质数 的 解 本题中n>=1 特判p=2 ...
- 045、安装Docker Machine (2019-03-08 周五)
参考https://www.cnblogs.com/CloudMan6/p/7223599.html 前面我们的实验中只有一个docker host ,所有的容器都是运行在这一个host上的.但在 ...
- springboot(二十二)spring-boot使用AOP
https://blog.csdn.net/w05980598/article/details/79053209
- js强制将页面放到最大
<!DOCTYPE html> <html> <head> <title></title> <script language=&quo ...
- gethostbyname和gethostbyaddr
一.gethostbyname函数原型 #include <netdb.h> struct hostent *gethostbyname(const char *ghostname); 返 ...