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

Dynamic Programming. 最长增长子序列。推荐一个链接:http://www.cnblogs.com/liyukuneed/archive/2013/05/26/3090402.html。按照链接里的方法三(其他的会有TLE - time limit exceed),求得以ith element为尾的最长增长子序列的长度,以及以ith element为始的最长递减子序列的长度。代码如下:

 #include <iostream>
#include <math.h>
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <string>
#include <sstream>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <cmath>
#include <set>
#define SCF(a) scanf("%d", &a)
#define IN(a) cin>>a
#define FOR(i, a, b) for(int i=a;i<b;i++)
typedef long long Int;
using namespace std; int inLen[], deLen[]; int BSI(int input[], int list[], int n, int right, int record[]) //increase sub-string
{
if (input[list[right]] < input[n])
{
list[right + ] = n;
record[n] = right + ;
return right + ;
} if (input[list[]] > input[n])
{
list[] = n;
record[n] = ;
return right;
} int l = , r = right;
int mid = ; while (l < r - )
{
mid = (l + r) / ;
if (input[list[mid]] <= input[n])
{
l = mid;
}
else
{
r = mid;
}
} if (input[list[l]] < input[n])
{
if (input[list[l + ]] > input[n])
{
list[l + ] = n;
}
record[n] = l + ;
}
else if (input[list[l]] == input[n])
{
record[n] = l;
}
return right;
} int main()
{
int N;
int input[];
int increase[], decrease[];
int inlen = , delen = ;
while (SCF(N) != EOF)
{
FOR(i, , N)
{
SCF(input[i]);
} increase[] = ;
inlen = ;
inLen[] = ;
FOR(i, , N)
{
inlen = BSI(input, increase, i, inlen, inLen);
} decrease[] = N - ;
delen = ;
deLen[N - ] = ;
for (int i = N - ; i >= ; i--)
{
delen = BSI(input, decrease, i, delen, deLen);
} int maxLen = ;
FOR(i, , N)
{
if (min(inLen[i], deLen[i]) > maxLen)
maxLen = min(inLen[i], deLen[i]);
} printf("%d\n", maxLen * - );
}
return ;
}

UVA 10534 Wavio Sequence的更多相关文章

  1. LIS UVA 10534 Wavio Sequence

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

  2. uva 10534 Wavio Sequence LIS

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

  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 (LIS+暴力)

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

  5. 【UVa】Wavio Sequence(dp)

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

  6. UVA 10534 三 Wavio Sequence

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

  7. BNUOJ 14381 Wavio Sequence

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

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

  9. UVa 1584 Circular Sequence --- 水题

    UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...

随机推荐

  1. c# HashTable (哈希表)

    HashTable 哈希表 也是System.Collections集合下的数据结构类 它储存的也是Object类型的对象 但是它在内存中是散列排布的 因为这个特性,非常适合存储大量的数据 在Hash ...

  2. @SuppressLint("HandlerLeak"),或Handler使用有警告;

    随手写个Handler,然后飘黄,看着挺难受(黄色警告的大概意思:Handler可能会内存泄漏,推荐你用静态内部类+实例化弱引用): This Handler class should be stat ...

  3. Sql server 编写99乘法表

    Sql 组织编写语句 declare @one int,@tow int,@str varchar(100),@num intselect @one=1while(@one<=9)beginse ...

  4. python-web自动化-元素操作:windows窗口切换 / alert切换 / iframe切换

    1. windows窗口切换:切换到要操作的窗口 有多个窗口: 1. 触发新窗口的出现 2. 得知道新窗口是谁 -- 依据窗口的window_handle来识别窗口 3. 得到窗口的window_ha ...

  5. springboot发送邮件

    1.在发送端邮箱平台开通SMTP服务 1)以163邮箱为例: step 1: step 2: 2.编写代码: 1)添加发送邮箱maven依赖 <dependency> <groupI ...

  6. 三. html&JavaScript&ajax 部 分

    1. 判 断 第 二 个 日 期 比 第 一 个 日 期 大 如何用脚本判断用户输入的的字符串是下面的时间格式2004-11-21必须要保证用户 的输入是此格式,并且是时间,比如说月份不大于12等等, ...

  7. __get__ __set__ __delete__描述符

    描述符就是一个新式类,这个类至少要实现__get__ __set__ __delete__方法中的一种class Foo: def __get__(self, instance, owner): pr ...

  8. Win10系统进行远程桌面连接出现身份验证错误怎么办

    在win10系统中,自带有远程桌面连接功能,但是有时候会遇到一些问题,比如有不少用户反映说在进行远程桌面连接的时候,出现身份验证错误的情况,导致远程连接失败,接下来给大家分享一下Win10系统进行远程 ...

  9. TensorFlow学习之二

    二.常用操作符和基本数学函数 大多数运算符都进行了重载操作,使我们可以快速使用 (+ - * /) 等,但是有一点不好的是使用重载操作符后就不能为每个操作命名了. 1  算术操作符:+ - * / % ...

  10. 吴裕雄 python深度学习与实践(12)

    import tensorflow as tf q = tf.FIFOQueue(,"float32") counter = tf.Variable(0.0) add_op = t ...