Longest Ordered Subsequence
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 33943   Accepted: 14871

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
求最长上升子序列:
dp的求法,初始化时能够将a[0]初始化成一个比全部数小的值,或者是将dp[]全清为1,由于最长上升子序列中,会包括自身,所以最小为1
 
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[12000] , dp[12000] ;
int main()
{
int i , j , n , max1 ;
while(scanf("%d", &n)!=EOF)
{
memset(dp,0,sizeof(dp));
a[0] = -1 ;
for(i = 1 ; i <= n ; i++)
scanf("%d", &a[i]);
for(i = 1 ; i <= n ; i++)
for(j = 0 ; j < i ; j++)
if( a[j] < a[i] && dp[j]+1 > dp[i] )
dp[i] = dp[j] + 1 ;
max1 = 0 ;
for(i = 1 ; i <= n ; i++)
max1 = max(max1,dp[i]);
printf("%d\n", max1);
}
return 0;
}

poj2533--Longest Ordered Subsequence(dp:最长上升子序列)的更多相关文章

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

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

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

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

  3. 【POJ - 2533】Longest Ordered Subsequence (最长上升子序列 简单dp)

    Longest Ordered Subsequence 搬中文 Descriptions: 给出一个序列,求出这个序列的最长上升子序列. 序列A的上升子序列B定义如下: B为A的子序列 B为严格递增序 ...

  4. [POJ2533]Longest Ordered Subsequence<dp>

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

  5. 题解报告:poj 2533 Longest Ordered Subsequence(最长上升子序列LIS)

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

  6. POJ 2533 Longest Ordered Subsequence(最长上升子序列(NlogN)

    传送门 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subseque ...

  7. POJ - 2533 Longest Ordered Subsequence(最长上升子序列)

    d.最长上升子序列 s.注意是严格递增 c.O(nlogn) #include<iostream> #include<stdio.h> using namespace std; ...

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

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

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

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

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

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

随机推荐

  1. Python:爬取乌云厂商列表,使用BeautifulSoup解析

    在SSS论坛看到有人写的Python爬取乌云厂商,想练一下手,就照着重新写了一遍 原帖:http://bbs.sssie.com/thread-965-1-1.html #coding:utf- im ...

  2. D1-Linux-CentOS学习打卡

    从一月底开始萌生了想在继续学Python的时候,学一门新的操作系统. 在看很多程序员的JD时,很多都要求熟悉LINUX,并且奔方法里面也提到了在LINUX下的编程. ----------------- ...

  3. python优秀库 - 使用envelopes发送邮件

    这里有一个使用python自带lib发送邮件的例子(http://my.oschina.net/leejun2005/blog/74416),这里面讲解的很全面,可以供大家参考. 今天将的是使用env ...

  4. [转]lftp的致命错误:证书验证:不信任

    原文:http://rajaseelan.com/2011/12/18/lftp-fatal-error-certificate-verification-not-trusted/如果您使用lftp的 ...

  5. linq 总结

    linq 常用方法: top   var query=(from u in User ...).Take(10) dblinq的坑: 时间必须当参数传入,否则会报错 多个left join时,如果jo ...

  6. Windows Phone 8初学者开发—第13部分:设置LongListSelector中磁贴的样式

    原文 Windows Phone 8初学者开发—第13部分:设置LongListSelector中磁贴的样式 第13部分:设置LongListSelector中磁贴的样式 原文地址: http://c ...

  7. boost::bind的使用方法

    bind - boost 头文件: boost/bind.hpp bind 是一组重载的函数模板.用来向一个函数(或函数对象)绑定某些参数. bind的返回值是一个函数对象. 它的源文件太长了. 看不 ...

  8. OJ python答题结果"返回非零"

    最近在OJ上用python答题,偶尔会遇到结果“放回非零”的情况(Non-zero Exit Code) 总结了以下,目前知道的是这些: 1. 在python2中用了input(),或在python3 ...

  9. Gstreamer中加入�x265编解码器

    官方的当前gstreamer版本号还不支持x265编解码,因此要加入�x265,须要自己编译.本文基于gstreamer1.3.3版进行编译安装.须要首先自己编译gstreamer1.3.3,以及对应 ...

  10. java.text.NumberFormat使用方法

    NumberFormat 是全部数值格式的抽象基类. 该类提供了格式化和分析数值的接口. NumberFormat 也提供了确定 哪个语言环境具有数值格式以及它们名字的方法. package com. ...