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. Dojo实现Tabs页报错(三)

    用Dojo实现tab页的过程中,没有引用“on.js”,但是firebug调试时一直提示如下错误: on.js源码如下: define(["./has!dom-addeventlistene ...

  2. Android 开发笔记 “Android 的消息队列模型”

    Android是参考Windows的消息循环机制来实现Android自身的消息循环的. Android通过Looper.Handler来实现消息循环机制,Android消息循环是针对线程的(每个线程都 ...

  3. python第二步,类对象部分

    类创建: class 类名: '类说明' def __init__ (self,参数):#类似php类的构造函数,self不知道什么东东 方法体 实例创建: 变量名 = 类名() #构造函数后的参数, ...

  4. PROPAGATION_REQUIRED

    PROPAGATION_REQUIRED (2009-05-13 13:26:52) 转载▼   事务传播行为种类 Spring在TransactionDefinition接口中规定了7种类型的事务传 ...

  5. Java中static、final用法

    一.final 1.final变量: 当你在类中定义变量时,在其前面加上final关键字,那便是说,这个变量一旦被初始化便不可改变,这里不可改变的意思对基本类型来说是其值不可变,而对于对象变量来说其引 ...

  6. linux搭建java环境

    建议使用EXCEL查看 准备文件 apache-tomcat-7.0.57.tar tomcat web容器 server-jre-7u76-linux-x64.tar  java jdk java执 ...

  7. [置顶] NGINX原理分析之SLAB分配机制

    一.基础概述 如果使用伙伴系统分配和释放算法,不仅会造成大量的内存碎片,同时处理效率也比较低.SLAB是一种内存管理机制,其核心思想是预分配.SLAB是将空间按照SIZE对内存进行分类管理的,当申请一 ...

  8. android中menu菜单的简单使用

    我认为menu用起来简洁方便,特别是在一些大一点的程序中我们早就厌烦了一遍遍的加button,设置了菜单可谓是事半功倍,简单省事. <1>先声明定义下你的menu: private sta ...

  9. BZOJ 1026: [SCOI2009]windy数( dp )

    dp..dp(x, t) 表示共x位, 第x位为t有多少个windy数. 对答案差分, 我们只需统计1 ~ l-1和1 ~ r的windy数数量. 考虑如何计算[1, n]的答案 : 从最高位到最低位 ...

  10. android:music

    package com.terry; import java.io.File; import java.io.FileFilter; import java.io.IOException; impor ...