LIS UVA 10534 Wavio Sequence
题意:找对称的,形如:123454321 子序列的最长长度
分析:LIS的nlogn的做法,首先从前扫到尾,记录每个位置的最长上升子序列,从后扫到头同理。因为是对称的,所以取较小值*2-1再取最大值
代码:
/************************************************
* Author :Running_Time
* Created Time :2015-8-5 21:38:32
* File Name :UVA_10534.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e4 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int a[MAXN];
int d[MAXN];
int dp[MAXN], dp2[MAXN]; int main(void) { //UVA 10534 Wavio Sequence
int n;
while (scanf ("%d", &n) == 1) {
for (int i=1; i<=n; ++i) scanf ("%d", &a[i]);
memset (d, 0, sizeof (d));
memset (dp, 0, sizeof (dp));
memset (dp2, 0, sizeof (dp2));
d[1] = a[1]; int len = 1; dp[1] = 1;
for (int i=2; i<=n; ++i) {
if (d[len] < a[i]) d[++len] = a[i];
else {
int j = lower_bound (d+1, d+1+len, a[i]) - d;
d[j] = a[i];
}
dp[i] = len;
}
d[1] = a[n]; int len2 = 1; dp2[n] = 1;
for (int i=n-1; i>=1; --i) {
if (d[len2] < a[i]) d[++len2] = a[i];
else {
int j = lower_bound (d+1, d+1+len2, a[i]) - d;
d[j] = a[i];
}
dp2[i] = len2;
}
int ans = 0;
for (int i=1; i<=n; ++i) {
ans = max (ans, min (dp[i], dp2[i]) * 2 - 1);
}
printf ("%d\n", ans);
} return 0;
}
LIS UVA 10534 Wavio Sequence的更多相关文章
- uva 10534 Wavio Sequence LIS
// uva 10534 Wavio Sequence // // 能够将题目转化为经典的LIS. // 从左往右LIS记作d[i],从右往左LIS记作p[i]; // 则最后当中的min(d[i], ...
- UVa 10534 Wavio Sequence (最长递增子序列 DP 二分)
Wavio Sequence Wavio is a sequence of integers. It has some interesting properties. · Wavio is of ...
- UVa 10534 Wavio Sequence (LIS+暴力)
题意:给定一个序列,求一个最长子序列,使得序列长度为奇数,并且前一半严格递增,后一半严格递减. 析:先正向和逆向分别求一次LIS,然后再枚举中间的那个数,找得最长的那个序列. 代码如下: #pragm ...
- UVA 10534 Wavio Sequence
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=17&p ...
- 【UVa】Wavio Sequence(dp)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 10534 三 Wavio Sequence
Wavio Sequence Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Sta ...
- BNUOJ 14381 Wavio Sequence
Wavio Sequence Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Origina ...
- 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 1584 Circular Sequence --- 水题
UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...
随机推荐
- Linux下汇编语言学习笔记60 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- android_handler(二)
这篇记录 android 消息机制中.WorkThread 模拟向网络訪问数据,获得数据后,返回 message 发送给 MainThread ,并改动 TextView 的 text 的这种一个步骤 ...
- 踩坑录-利用Apche-POI.XSSFWorkbook.write,处理excel文件,通过response.outputstram下载文件,预览乱码。
问题概要 利用Apche-POI.XSSFWorkbook.write,处理excel文件,通过response.outputstram导出文件,预览乱码. 解决办法 1.检查设置response,代 ...
- HDMI信号解析
参考资料:http://blog.sina.com.cn/s/blog_6cfd49b00102w00i.html: http://blog.csdn.net/gtkknd/article/detai ...
- 2011:Audio Classification (Train/Test) Tasks - MIREX Wiki
Contents [hide] 1 Audio Classification (Test/Train) tasks 1.1 Description 1.1.1 Task specific mailin ...
- 基于百度AI人脸识别技术的Demo
编写demo之前首先浏览官方API:http://ai.baidu.com/docs#/Face-API/top 下面是源码: package com.examsafety.test; import ...
- flask的nocache防止js不刷新
原文:http://librelist.com/browser/flask/2011/8/8/add-no-cache-to-response/#952cc027cf22800312168250e59 ...
- node inspector的安装以及使用【已经淘汰了】
https://github.com/node-inspector/node-inspector 前提 1.npm install -g node-pre-gyp https://github.com ...
- bzoj 4337 树的同构
4337: BJOI2015 树的同构 Description 树是一种很常见的数据结构. 我们把N个点,N-1条边的连通无向图称为树. 若将某个点作为根,从根开始遍历,则其它的点都有一个前驱,这个树 ...
- 4.2 Context-Free Grammars
4.2 Context-Free Grammars Grammars were introduced in Section 2.2 to systematically describe the syn ...