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 ...
随机推荐
- springboot 修改页面不重启
shifr+alt+commond+/ <!-- 热部署模块 --><dependency> <groupId>org.springframework.boot&l ...
- Haproxy 安装初体验
20180916 haproxy Haproxy简介 Haproxy是一款免费的.快速的和稳定的解决方案,提供HA和LB功能,同时对基于TCP的应用和HTTP的应用进行代理,对于流量很大的web站点来 ...
- opencv源码学习: getStructuringElement函数;
getStructuringElement函数归属于形态学,可以建立指定大小.形状的结构: 原型: /** @brief Returns a structuring element of the sp ...
- Office-kms
Office 2016 VOL Office Office 2016 Pro Plus 32 位专业增强版 文件名 SW_DVD5_Office_Professional_Plus_2016_W32_ ...
- JAVA核心技术I---JAVA基础知识(单例模式和final关键字)
一:单例模式 C++设计模式中提及,不再赘述设计模式---对象性能模式之单例模式(Singleton) public class single{ static single Instance=new ...
- spring整合ActiveMq
spring整合ActiveMq: 1:依赖的jar包: 2:spring-activemq.xml 的配置: 代码: <?xml version="1.0" enco ...
- 查看swap占用情况
查看swap被占用的情况 #!/bin/bash # Get current swap usage for all running processes # Erik Ljungstrom 27/05/ ...
- JavaSE回顾及巩固的自学之路(三)——————所有语言的都存在的基本运算
在上一篇的博客中,我回顾到Java中的关键字,标识符等知识点,而今天这篇博文将回顾Java的,哦,不,不止Java,据本人了解,几乎在所有的语言中的基础阶段,都会存在这些运算,只是语法不一样而已. 今 ...
- RMQ st算法 区间最值模板
#include<bits/stdc++.h> ; ; int f[N][Logn],a[N],lg[N],n,m; int main(){ cin>>n>>m; ...
- tensorflow--logistic regression
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist=input_data. ...