UVA - 10543 LIS
题意:见大白Page93
真没想到是两边分别设为终点和起点的LIS和..LDS?
注意,要求对称,所以分别取min
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e5+11;
const double eps = 1e-10;
typedef long long ll;
const int oo = 0x3f3f3f3f;
const double ERR = -2.3333;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int dp[maxn],a[maxn],n;
int dp2[maxn],b[maxn];
int tmp1[maxn],tmp2[maxn];
int main(){
while(cin>>n){
rep(i,1,n) b[i]=a[i]=read();
reverse(b+1,b+1+n);
memset(dp,0x3f,sizeof dp);
memset(dp2,0x3f,sizeof dp2);
rep(i,1,n){
int pos=lower_bound(dp+1,dp+n,a[i])-dp;
dp[pos]=a[i];
tmp1[i]=pos;
}
rep(i,1,n){
int pos=lower_bound(dp2+1,dp2+1+n,b[i])-dp2;
dp2[pos]=b[i];
tmp2[i]=pos;
}
int ans=-oo;
rep(i,1,n){
ans=max(min(tmp1[i],tmp2[n-i+1])*2-1,ans);
}
println(ans);
}
return 0;
}
UVA - 10543 LIS的更多相关文章
- UVa 10635 (LIS+二分) Prince and Princess
题目的本意是求LCS,但由于每个序列的元素各不相同,所以将A序列重新编号{1,2,,,p+1},将B序列重新编号,分别为B中的元素在A中对应出现的位置(没有的话就是0). 在样例中就是A = {1 7 ...
- UVa 1471 (LIS变形) Defense Lines
题意: 给出一个序列,删掉它的一个连续子序列(该子序列可以为空),使得剩下的序列有最长的连续严格递增子序列. 分析: 这个可以看作lrj的<训练指南>P62中讲到的LIS的O(nlogn) ...
- UVA - 10635 LIS LCS转换
白书例题,元素互不相同通过哈希转换为LIS求LCS #include<iostream> #include<algorithm> #include<cstdio> ...
- What Goes Up UVA - 481 LIS+打印路径 【模板】
打印严格上升子序列: #include<iostream> #include<cstdio> #include<algorithm> #include<cst ...
- Uva 10131 Is Bigger Smarter? (LIS,打印路径)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=1072">链接:UVa 10131 题意: ...
- LIS UVA 10534 Wavio Sequence
题目传送门 题意:找对称的,形如:123454321 子序列的最长长度 分析:LIS的nlogn的做法,首先从前扫到尾,记录每个位置的最长上升子序列,从后扫到头同理.因为是对称的,所以取较小值*2-1 ...
- uva 10534 Wavio Sequence LIS
// uva 10534 Wavio Sequence // // 能够将题目转化为经典的LIS. // 从左往右LIS记作d[i],从右往左LIS记作p[i]; // 则最后当中的min(d[i], ...
- UVA 10635 - Prince and Princess LCS转化为LIS
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- Uva 10635 - Prince and Princess LCS/LIS
两个长度分别为p+1和q+1的由1到n2之前的整数组成的序列,每个序列的元素各不相等,两个序列第一个元素均为1.求两个序列的最长公共子序列 https://uva.onlinejudge.org/in ...
随机推荐
- win32 多线程 (五)Event
Event是内核对象,他可以分为自动和手动两种模式. HANDLE CreateEvent( LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManual ...
- pymysql模块使用---Python连接MySQL数据库
pymysql模块使用---Python连接MySQL数据库 浏览目录 pymysql介绍 连接数据库 execute( ) 之 sql 注入 增删改查操作 进阶用法 一.pymysql介绍 1.介绍 ...
- hdu 2553 N皇后问题(一维数组详尽解释)
//一维数组解法(注释详尽)//num皇后可以表示第num列,然后枚举num皇后所在的行//二维数组对角线转换为坐标的关系#include<stdio.h> #include<str ...
- js 二维数组排序sort()函数
一.按数值排序 var arr = [[1, 2, 3], [7, 2, 3], [3, 2, 3]]; arr.sort(function(x, y){ return x[0] – y[0];}) ...
- Daubechies Wavelet
The Daubechies wavelets, based on the work of Ingrid Daubechies, are a family of orthogonal wavelets ...
- 服务器控件数据回发实现IPostBackDataHandler需注意的
我写的服务器控件(未完,模型如此) using System; using System.Collections.Generic; using System.Collections.Specializ ...
- Vue vue-resource发送Http请求
vue-resource 1.cnpm install vue-resource --save 2.在main.js中import VueResource from 'vue-resource' 3. ...
- git配置本地环境(phpstudy/tortoisegit/git等)
1.下载安装phpstudy 2.下载安装git 下载地址:https://git-scm.com/downloads 3.下载安装tortoisegit,电脑64位就下载这个,如图: 4.下载安装“ ...
- MySQL学习笔记(一):查询
查询实例: 1.创建数据库并使用: create database school; use school; 2.创建表并插入内容: create table student( Sno char(9) ...
- WKWebView 的使用和封装
WKWebView 的使用和封装 前言 项目中有个新闻资讯模块展示公司和相关行业的最新动态. 这个部分基本是以展示网页为主,内部可能会有一些 native 和 JS 代码的交互. 因为是新项目,所以决 ...