知识大全 UVA 10534 Wavio Sequence(dp + LIS)
Posted 序列
篇首语:业精于勤,荒于嬉。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 UVA 10534 Wavio Sequence(dp + LIS)相关的知识,希望对你有一定的参考价值。
UVA 10534 Wavio Sequence(dp + LIS) 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
Wavio is a sequence of integers It has some interesting properties
· Wavio is of odd length i e L = *n +
· The first (n+ ) integers of Wavio sequence makes a strictly increasing sequence
· The last (n+ ) integers of Wavio sequence makes a strictly decreasing sequence
· No o adjacent integers are same in a Wavio sequence
For example is an Wavio sequence of length But is not a valid wavio sequence In this problem you will be given a sequence of integers You have to find out the length of the longest Wavio sequence which is a subsequence of the given sequence Consider the given sequence as :
Here the longest Wavio sequence is : So the output will be
Input
The input file contains less than test cases The description of each test case is given below: Input is terminated by end of file
Each set starts with a postive integer N( <=N<= ) In next few lines there will be N integers
Output
For each set of input print the length of longest wavio sequence in a line Sample Input Output for Sample Input
Problemsetter: Md Kamruzzaman Member of Elite Problemsetters&# ; Panel
题意 求出最长的波形序列 波形序列为前半部分上升后半部分下降 长度相同
思路 一开始以为是水水的LIS问题 可是n有 W 用基本的dp复杂度为O(n^ ) 果断超时了 然后去了解了下一种算法 i表示前i个数字组成的序列 原来的做法是i遍历一遍为O(n) 然后在i里面遍历一遍查找满足条件的最长序列为O(n)总复杂度为O(N^ ) 现在查找满足条件换个方式 先把序列保存下来 如果最后一个数字大 直接加在序列位置 否则用二分查找法 找到适当位置插入 这样复杂度为O(logn) 总复杂度为O(nlogn) 不过这总方法保存只能求长度 保存下得序列并不能满足题目
代码
cha138/Article/program/Web/201405/30988相关参考