// 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. reportlab使用示例:文字和图片

    Python的reportlab专门将数据使用生成PDF中的图形和文档功能, 下载ReportLab https://pypi.python.org/simple/reportlab/ http:// ...

  2. NOIP2012D2T1 同余方程

    [NOIP2012T4]同余方程 noip2012-tg 描述 求关于 x的同余方程 ax ≡ 1(mod b) 的最小正整数解. 输入格式 输入文件 mod.in 输入只有一行,包含两个正整数a,b ...

  3. Python 之 风格规范(Google )

    开头先mark一下网址:goole官网 任何语言的程序员,编写出符合规范的代码,是开始程序生涯的第一步. 一.分号 不要在行尾加分号, 也不要用分号将两条命令放在同一行. 二.行长度 每行不超过80个 ...

  4. jquery mobile datepicker

    1.http://jquerymobile.com/demos/1.0a4.1/experiments/ui-datepicker/ 这个只能用在iOS和PC上,使用<input date,An ...

  5. DELPHI调试出现disconnected session的解决办法

    我在控制面板中,是禁用了UAC的,如下图 但是,在注册表中启用了UAC(EnableLUA), 工程中请求了管理员权限,如下图: 所以,整个权限请求混乱了. 解决办法,要么把注册表的LUA设置为0,要 ...

  6. C++序列化使用

    error C2248 无法访问私有成员 :原因 ifstream 作为参数必须传引用! (1):C++使用STL序列化:原文链接:http://blog.csdn.net/pandaxcl/arti ...

  7. Lazy Initialization with Swift

    Lazy initialization (also sometimes called lazy instantiation, or lazy loading) is a technique for d ...

  8. AssemblyInfo.cs 文件信息

    using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices ...

  9. 基于 vue2 导航栏透明渐变

    在移动或者app 中经常会用,顶部导航栏固定,但是随着页面向上滚动,导航栏的透明度发生变化. 做法为: 1.首先给要滚动变化的导航添加 :style="style" <mt- ...

  10. forEach 列出数组的每个元素:

    数组.forEach便利所有的元素 array.forEach(function(currentValue, index, arr), thisValue) function(currentValue ...