Longest Ordered Subsequence
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 41984   Accepted: 18481

Description

A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1a2, ..., aN) be any sequence (ai1ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK<= N. For example, sequence (1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8).

Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.

Input

The first line of input file contains the length of sequence N. The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000

Output

Output file must contain a single integer - the length of the longest ordered subsequence of the given sequence.

Sample Input

7
1 7 3 5 9 4 8

Sample Output

4

Source

Northeastern Europe 2002, Far-Eastern Subregion

[Submit]   [Go Back]   [Status]   [Discuss]

 #include<cstdio>
#include<iostream>
using namespace std; int main()
{
int n, a[], cn = , Maxlenth[], M = ;
cin >> n;
for(int i = ; i < n; i++) {
cin >> a[i];
Maxlenth[i] = ;
}
for(int i = n - ; i >= ; i--) {
for(int j = i + ; j < n; j++) {
if(a[i] < a[j] && Maxlenth[i] <= Maxlenth[j]) Maxlenth[i] = + Maxlenth[j];
if(Maxlenth[i] > M) M = Maxlenth[i];
}
}
cout << M << endl;
return ;
}

POJ2533 Longest ordered subsequence的更多相关文章

  1. POJ2533——Longest Ordered Subsequence(简单的DP)

    Longest Ordered Subsequence DescriptionA numeric sequence of ai is ordered if a1 < a2 < ... &l ...

  2. POJ2533 Longest Ordered Subsequence 【最长递增子序列】

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 32192   Acc ...

  3. (线性DP LIS)POJ2533 Longest Ordered Subsequence

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 66763   Acc ...

  4. poj-2533 longest ordered subsequence(动态规划)

    Time limit2000 ms Memory limit65536 kB A numeric sequence of ai is ordered if a1 < a2 < ... &l ...

  5. POJ2533 Longest Ordered Subsequence —— DP 最长上升子序列(LIS)

    题目链接:http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 6 ...

  6. [POJ2533]Longest Ordered Subsequence<dp>

    题目链接:http://poj.org/problem?id=2533 描述: A numeric sequence of ai is ordered if a1 < a2 < ... & ...

  7. POJ-2533.Longest Ordered Subsequence (LIS模版题)

    本题大意:和LIS一样 本题思路:用dp[ i ]保存前 i 个数中的最长递增序列的长度,则可以得出状态转移方程dp[ i ] = max(dp[ j ] + 1)(j < i) 参考代码: # ...

  8. POJ2533 Longest Ordered Subsequence (线性DP)

    设dp[i]表示以i结尾的最长上升子序列的长度. dp[i]=max(dp[i],dp[j]+1). 1 #include <map> 2 #include <set> 3 # ...

  9. POJ2533:Longest Ordered Subsequence(LIS)

    Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence ...

随机推荐

  1. spring 读取properties的两种方法

    一:直接使用context命名空间 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi= ...

  2. codevs1044四子连棋(Dfs)

    /* 数据范围太小 暴力暴力 Dfs直接 终止条件嘛 就是4中目标棋局 挨着枚举一遍就好了 搜索的起点一定是空格 当然 空格周围有黑有白 黑先走或者白先走答案可能不一样 所以 维护一个b 表示这一步走 ...

  3. HighCharts基本用法

    var options={ chart: {type: 'column',renderTo: 'ChartDesigner1'},//type :图表类型(柱状图,饼状图),renderTo :指向页 ...

  4. 后台地址报错:Service Unavailable

    首先考虑数据库是否打开? 第二重启IIS试试: 重启下iis试试(cmd接着iisreset) 再次访问就正常了,可以借鉴,但不一定就只是这一种原因.

  5. 关于<:if>没有<c:else>解决方案

    <c:if>没有<c:else>可以用<c:choose>来取代结构: <c:choose> <c:when test=""& ...

  6. 简单实现图片间的切换动画 主要用到ViewPager

    简单实现图片间的切换动画 主要用到ViewPagerViewPager是android扩展包v4包中的类,这个类可以让用户左右切换当前的view.ViewPager类需要一个PagerAdapter适 ...

  7. AlertView + Block 的使用

    AlertView的使用还是很频繁的,扁平化以后似乎也不是那么丑了,但是到现在为止官方还是在用Delegate来处理点击事件,很影响程序的可读性. 如果用Block那么就会一目了然.自己本来想写一个, ...

  8. 【HAOI2011】向量

    [题目描述] 给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)这些向量,问你能不能拼出另一个 ...

  9. Cookie、LocalStorge、SesstionStorge 的区别和用法

    前言 总括:详细讲述Cookie.LocalStorge.SesstionStorge的区别和用法. 1. 各种存储方案的简单对比 Cookies:浏览器均支持,容量为4KB UserData:仅IE ...

  10. 面向对象设计模式之Flyweight享元模式(结构型)

    动机:采用纯粹对象方案的问题在于大量细粒度的对象会很快充斥在系统中,从而带来很高的运行代价——主要指内存需求方面的代价.如何在避免大量细粒度对象问题的同 时,让外部客户程序仍然能够透明地使用面向对象的 ...