题目链接: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. Chapter 5 数组:为什么很多编程语言种数组都是从0开始编号?

    如何实现随机访问? 线性表:数组,队列,链表,栈 非线性表:树,图 总结:数组用一块连续的内存空间,来存储相同类型的一组数据,最大的特点就是支持随机访问,但插入,删除操作也因此变得比较低效,平均情况时 ...

  2. 第二章 Java内存区域与内存溢出异常

    运行时数据区域: 程序计数器(Program Counter Register):当前线程执行码行号指示器,属于线程私有内存.字节码解释器工作时就是通过调整这个计数器的值来选取下一条需要执行字节码指令 ...

  3. MSB8013

    解决方案: 去掉勾选

  4. python大法好——网络编程

    Python 网络编程 Python 提供了两个级别访问的网络服务.: 低级别的网络服务支持基本的 Socket,它提供了标准的 BSD Sockets API,可以访问底层操作系统Socket接口的 ...

  5. centos7 卸载 jdk

    ################ jdk 的安装 ###########################参考:https://www.cnblogs.com/Dylansuns/p/6974272.h ...

  6. ABAP-表中数据的横向累加

    GLT0 等表中数据的横向累加 ——塞依SAP培训   在 ABAP 的 GLT0.FAGLFLEXT 等余额表中,用诸如 TSL01.TSL02 …… TSL16 等字段记录了 16 个期间的发生额 ...

  7. MySql:SELECT 语句(三) WHERE 指定查询条件

    1.WHERE 子句条件操作符 包括:> .<.>=.<=.!= .=.BETWEEN ... AND ...(在指定的两个值之间) 示例: 1)select * from s ...

  8. java学习--equals

    Object类是所有类的基类. Object类有equals方法.而继承Object中的equals方法判断的是两个对象的引用是否相等,相当于"==",也就是说只有比较的两个对象为 ...

  9. Unity 获取指定资源目录下的所有文件

    string path="Assets";//Assets/Scenes if(Directory.Exists(path)){ var dirctory=new Director ...

  10. CSS3 Box-sizing(转载)

    转载自:W3CPLUS Airen的博客:http://www.w3cplus.com/content/css3-box-sizing box-sizing是CSS3的box属性之一.一说到CSS的盒 ...