// uva 10534 Wavio Sequence
//
// 能够将题目转化为经典的LIS。
// 从左往右LIS记作d[i],从右往左LIS记作p[i];
// 则最后当中的min(d[i],p[i])就是这个波动序列的一半
// 在这最后的min(d[i],p[i]) * 2 + 1 的最大值就是我们所要求的答案
//
// 这题開始想的最后的答案是d[i]==p[i]的时候求最大。 // 可是这样是不正确的,比如n=4,
// 1,3,1,0
// 最长的应该是3,可是我的答案是1,明显是错的
//
// 细致想来,确实是这样。仅仅要取min(d[i],p[i])的最小值作为一半就能够了
//
// 还是欠缺考虑。继续练 #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ceil(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define gcd __gcd
#define highBit(x) (1ULL<<(63-__builtin_clzll(x)))
#define popCount __builtin_popcountll
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const long double PI = acos(-1.L); const int maxn = 10008;
const int inf = 0x7f7f7f7f;
int a[maxn];
int b[maxn];
int d[maxn];
int p[maxn];
int g[maxn];
int n; void lis(int a[],int d[]){
memset(g,inf,sizeof(g));
int k;
for (int i=1;i<=n;i++){
k = lower_bound(g+1,g+n+1,a[i])-g;
d[i] = k;
g[k] = a[i];
}
} void print(int a[]){
for (int i=1;i<=n;i++){
printf("%d ",a[i]);
}
puts("");
} void init(){
for (int i=1;i<=n;i++){
scanf("%d",&a[i]);
b[n-i+1] = a[i];
}
memset(d,inf,sizeof(d));
memset(p,inf,sizeof(p));
lis(a,d);
lis(b,p);
int ans = 1;
for (int i=1;i<=n;i++){
// if (d[i]==p[n-i+1]){
// cout << i << "----" << d[i] << endl;
// ans = max(ans,d[i] * 2 - 1);
// }
ans = max(ans,min(d[i],p[n-i+1]) * 2 - 1);
}
printf("%d\n",ans);
print(d);
print(p);
} int main() {
//freopen("E:\\Code\\1.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
init();
}
return 0;
}

uva 10534 Wavio Sequence LIS的更多相关文章

  1. UVa 10534 Wavio Sequence (LIS+暴力)

    题意:给定一个序列,求一个最长子序列,使得序列长度为奇数,并且前一半严格递增,后一半严格递减. 析:先正向和逆向分别求一次LIS,然后再枚举中间的那个数,找得最长的那个序列. 代码如下: #pragm ...

  2. LIS UVA 10534 Wavio Sequence

    题目传送门 题意:找对称的,形如:123454321 子序列的最长长度 分析:LIS的nlogn的做法,首先从前扫到尾,记录每个位置的最长上升子序列,从后扫到头同理.因为是对称的,所以取较小值*2-1 ...

  3. UVa 10534 Wavio Sequence (最长递增子序列 DP 二分)

    Wavio Sequence  Wavio is a sequence of integers. It has some interesting properties. ·  Wavio is of ...

  4. UVA 10534 Wavio Sequence

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=17&p ...

  5. 【UVa】Wavio Sequence(dp)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  6. UVa10534 - Wavio Sequence(LIS)

    题目大意 给定一个长度为n的整数序列,求个最长子序列(不一定连续),使得该序列的长度为奇数2k+1,前k+1个数严格递增,后k+1个数严格递减.注意,严格递增意味着该序列中的两个相邻数不能相同.n&l ...

  7. UVA 10534 三 Wavio Sequence

    Wavio Sequence Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Sta ...

  8. BNUOJ 14381 Wavio Sequence

    Wavio Sequence Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Origina ...

  9. 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 ...

随机推荐

  1. 院校-美国:麻省理工学院(MIT)

    ylbtech-院校-美国:麻省理工学院(MIT) 麻省理工学院(Massachusetts Institute of Technology),简称麻省理工(MIT),坐落于美国马萨诸塞州波士顿都市区 ...

  2. First step in troubleshooting complex issues: Define and scope your issue properly

    最近在查调试相关资料的时候,无意看到Tess的一篇关于如何快速分析复合场景问题的博文,感觉很实用,Mark备忘. My 9 questions for a pretty thorough proble ...

  3. js---通过arguments来获取指定参数

    通过访问arguments对象的length属性可以获取有多少个参数传递给了函数. 如:每次被调用的时候,输出传入其中的参数个数 function doAdd(){ alert(arguments.l ...

  4. vue-cli 结构

    . |-- build                            // 项目构建(webpack)相关代码 |   |-- build.js                     // ...

  5. SqlServer与MySql 系统表查询自建表数据

    SqlServer: SELECT * FROM sys.sysobjects WHERE type='U' ORDER BY name SELECT * FROM sys.syscolumns WH ...

  6. deeplearning4j – 分布式DL开源项目

    原文链接:http://www.52ml.net/16157.html Deeplearning4j is the first commercial-grade deep learning libra ...

  7. cordova 打包工具

    一.环境安装 1.安装NodeJs https://nodejs.org 直接去官网下载并按默认路径安装就可以了. 安装完成后在命令行:   (测试成功!) $ npm 2.安装Cordova 命令行 ...

  8. Linux终端 Tab 补全命令

    1. vi编辑器打开 /etc/bash.bashrc文件 vi /etc/bash.bashrc 2.找到文件中的下列代码 3.将注释符号#去掉,即改成 4.最后 source一下 /etc/bas ...

  9. springboot-简介

    SpringBoot是Spring项目中的一个子工程,与我们所熟知的Spring-framework 同属于spring的产品: 下载地址: Spring Boot 主要目标是: 为所有 Spring ...

  10. gradle多模块构建集成swagger

    1.首先说一下软件的版本:springboot:1.5.2:springcloud:D-SR1:swaager2:2.6.0:gradle:4.5.工程模块是分开的单独的entity,api,mapp ...