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 ...
随机推荐
- go的net/http用法
http包提供了HTTP客户端和服务端的实现 一:http客户端的几种方法 1. func (c *Client) Get(url string) (resp *Response, err error ...
- MySQL数据库详解之"双1设置"的数据安全的关键参数案例分享
mysql的"双1验证"指的是innodb_flush_log_at_trx_commit和sync_binlog两个参数设置,这两个是是控制MySQL 磁盘写入策略以及数据安全性 ...
- 【XShell】xshell评估过期解决办法
1.登录网景官网的下载页面: 官网:https://www.netsarang.com/download/down_form.html?code=522 2.填写基本信息 licensetype 必须 ...
- net-snmp开发教程
目录 1................................................................................................ ...
- javascript中click和onclick的区别
<script type="text/javascript"> $(function(){ $("#btn4").click(function(){ ...
- ruby数组操作方法汇总
1.数组定义 arr1 = [] arr2 = Array.new arr3 = ['1','2','3'] 2.输出 print arr3,"\n" #123 puts arr3 ...
- Integer与int值的比较
==一般用于比较内存地址,equals()用于比较Object的值,注意int用equals()是会报错的.Integer i=1Integer k=1i.equals(k)=truei==k=tru ...
- 【1】【leetcode-115】 不同的子序列 distinct-subsequences
不同的子序列 distinct-subsequences(hard) (忘了,典型) 给定一个字符串 S 和一个字符串 T,计算在 S 的子序列中 T 出现的个数. 一个字符串的一个子序列是指,通过删 ...
- Java高并发秒杀API之web层
第1章 设计Restful接口 1.1前端交互流程设计 1.2 学习Restful接口设计 什么是Restful?它就是一种优雅的URI表述方式,用来设计我们资源的访问URL.通过这个URL的设计,我 ...
- Ext.net NumberField要设置MinValue,MaxValue
<Items> <ext:NumberField ID="NumberField1" runat="server" FieldLabel=&q ...