题意:给定一个序列,求一个最长子序列,使得序列长度为奇数,并且前一半严格递增,后一半严格递减。

析:先正向和逆向分别求一次LIS,然后再枚举中间的那个数,找得最长的那个序列。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 10000 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int dp1[maxn], dp2[maxn], dp[maxn];
int a[maxn]; int solve(){
int ans = 0;
for(int i = 1; i < n; ++i){
ans = max(ans, min(dp1[i], dp2[i])*2 + 1);
}
return ans;
} int main(){
while(scanf("%d", &n) == 1){
for(int i = 0; i < n; ++i) scanf("%d", a+i);
memset(dp, INF, sizeof dp);
for(int i = 0; i < n; ++i){
*lower_bound(dp, dp+n, a[i]) = a[i];
dp1[i] = lower_bound(dp, dp+i+1, INF) - dp - 1;
}
memset(dp, INF, sizeof dp);
for(int i = n-1; i >= 0; --i){
*lower_bound(dp, dp+n, a[i]) = a[i];
dp2[i] = lower_bound(dp, dp+n, INF) - dp - 1;
}
printf("%d\n", solve());
}
return 0;
}

UVa 10534 Wavio Sequence (LIS+暴力)的更多相关文章

  1. uva 10534 Wavio Sequence LIS

    // uva 10534 Wavio Sequence // // 能够将题目转化为经典的LIS. // 从左往右LIS记作d[i],从右往左LIS记作p[i]; // 则最后当中的min(d[i], ...

  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. poj 2151Check the difficulty of problems<概率DP>

    链接:http://poj.org/problem?id=2151 题意:一场比赛有 T 支队伍,共 M 道题, 给出每支队伍能解出各题的概率~  求 :冠军至少做出 N 题且每队至少做出一题的概率~ ...

  2. linux rsyncserver文件同步

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zqtsx/article/details/24254651 [root@zqtsx]# rpm -q ...

  3. matlab使用usb和gige 网口相机

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 辛苦原创所得,转载请注明出处 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ...

  4. 从动态库的def文件生成lib文件

    以sqlite3为例,下载的文件中只有def文件,没有lib文件,想使用静态方式调用dll的情况下,就需要额外的.h文件和.lib文件存在. .h文件可以从官方下载的sqlite-amalgamati ...

  5. Linux桥接网络配置

    在虚拟机网络配置中,选择桥接的方式.然后进入linux进行设置. 编辑 vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPR ...

  6. 本地Ubuntu16搭建Seafile

    本地搭建Seafile 1.下载 2.解压 3.创建目录 mySeafile 4.将解压包放入mySeafile中 5.创建installed 将压缩包放入installed 安装准备工作 pytho ...

  7. 配置 git 以ssh公钥访问github

    #生成ssh config touch .ssh/config chmod 600 config 填写: Host github.com User betachen Hostname ssh.gith ...

  8. linux应用之bugfree的安装及配置

    Bugfree3.0.4 Linux环境安装指南 bugfree系统安装的前提是,配置LAMP环境(apache+mysql+php),下面以centos6.3系统为例介绍bugfree3.0.4的安 ...

  9. 51nod【1196】字符串的数量

    超级神题! 有n种字符,若此种字符的编号( \(1\) ~ \(n\)),\(i*2>n\),则他后面可接任意字符.若不是,则他后面接的字符编号至少要是他的两倍. 问长度为m的字符串的个数. 这 ...

  10. openfire插件开发环境

    创建java工程 SamplePlugin: package com.hoo.server.plugin; import java.io.File; import org.jivesoftware.o ...