UVA 10534 Wavio Sequence
题目链接: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的更多相关文章
- LIS UVA 10534 Wavio Sequence
题目传送门 题意:找对称的,形如:123454321 子序列的最长长度 分析:LIS的nlogn的做法,首先从前扫到尾,记录每个位置的最长上升子序列,从后扫到头同理.因为是对称的,所以取较小值*2-1 ...
- 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】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个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...
随机推荐
- 减小delphi体积的方法
1.关闭RTTI反射机制 自从Delphi2010中引入了新的RTTI反射机制后,编译出来的程序会变得很大,这是因为默认情况下 Delphi2010 给所有类都加上了反射机制.而我们的工程并不每每都 ...
- msvcp140.dll丢失解决方案
[首先给出99%情况下都能解决这个问题的最简单办法]: 下载并安装微软VC++2015版运行库 (英文全称:Microsoft Visual C++ 2015 Redistributable Pa ...
- NFC应用于公交卡
NFC应用于公交卡https://www.cnblogs.com/liuzhaoyzz/p/7115098.html 带有NFC功能的安卓手机可以给实体公交卡充值,手机虚拟公交卡现在有两种方案,一种是 ...
- 常量&字符编码
day1 name='Nod Chen' name2=name print('My name is ',name,name2) name='Luna zhou' print(name,name2) _ ...
- MDI容器
MDI容器 具体步骤如下: private void 销售ToolStripMenuItem_Click(object sender, EventArgs e) { VisibledForm(); F ...
- 几种将上一个请求的cookies带入下一个请求中的方法
*** 此次练习不包含使用requests.session()方法实现: 练习环境:本地安装禅道 格式: 1.头部传Cookie:xxx2.加参数cookies=字典格式3.直接传RequestsCo ...
- Requests对HTTPS请求验证SSL证书
SSL证书通过在客户端浏览器和Web服务器之间建立一条SSL安全通道(Secure socket layer(SSL)安全协议是由Netscape Communication公司设计开发.该安全协议主 ...
- scrollview嵌套recyclerview显示不全现象
只需在recyclerview的外层加入一个父布局就好了 <RelativeLayout android:layout_width="match_parent" androi ...
- C++学习基础十六-- 函数学习笔记
C++ Primer 第七章-函数学习笔记 一步一个脚印.循序渐进的学习. 一.参数传递 每次调用函数时,都会重新创建函数所有的形参,此时所传递的实参将会初始化对应的形参. 「如果形参是非引用类型,则 ...
- jQuery.ajax()调用asp.net后台方法(非常重要)
http://www.cnblogs.com/zxhoo/archive/2011/01/30/1947752.html 用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. 先 ...