Longest Ordered Subsequence
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 32192   Accepted: 14093

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

NYOJ原题

#include <stdio.h>

int arr[1002], dp[1002];

int main()
{
int n, i, j, ans;
scanf("%d", &n);
for(i = 1; i <= n; ++i) scanf("%d", arr + i);
dp[1] = ans = 1;
for(i = 2; i <= n; ++i){
for(dp[i] = 1, j = i - 1; j >= 1; --j){
if(arr[i] > arr[j] && dp[i] <= dp[j]){
dp[i] = dp[j] + 1;
if(dp[i] > ans) ans = dp[i];
}
}
}
printf("%d\n", ans);
return 0;
}

POJ2533 Longest Ordered Subsequence 【最长递增子序列】的更多相关文章

  1. poj 2533 Longest Ordered Subsequence 最长递增子序列

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...

  2. POJ 2533 - Longest Ordered Subsequence - [最长递增子序列长度][LIS问题]

    题目链接:http://poj.org/problem?id=2533 Time Limit: 2000MS Memory Limit: 65536K Description A numeric se ...

  3. poj 2533 Longest Ordered Subsequence 最长递增子序列(LIS)

    两种算法 1.  O(n^2) #include<iostream> #include<cstdio> #include<cstring> using namesp ...

  4. leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence

    Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...

  5. POJ 2533 Longest Ordered Subsequence 最长递增序列

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

  6. zoj 2136 Longest Ordered Subsequence 最长上升子序列 新思路

    Longest Ordered Subsequence Time Limit: 2 Seconds      Memory Limit: 65536 KB A numeric sequence of ...

  7. [LintCode] Longest Increasing Subsequence 最长递增子序列

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

  8. [LeetCode] Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  9. [LeetCode] 300. Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Inp ...

  10. 673. Number of Longest Increasing Subsequence最长递增子序列的数量

    [抄题]: Given an unsorted array of integers, find the number of longest increasing subsequence. Exampl ...

随机推荐

  1. 【MySQL案件】ERROR 1665 (HY000)

    转载请注明: http://blog.csdn.net/jason_asia/article/details/36240815 1.1.1. ERROR 1665 (HY000) [环境的叙述性说明] ...

  2. asp.net mvc实现rest风格返回json

    实现类似:http://localhost:1799/rest/person/1方式返回一个json内容: 在asp.net mvc中新建一个control rest,然后在其中新增方法: publi ...

  3. iOS一个开发系列中 - UIButton 使用摘要

    // 初始化button并设置类型 UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // 可以定义的UIButto ...

  4. 3.1、Eclipse

    (原版的:http://www.libgdx.cn/topic/22/3-1-eclipse) 生成项目之后,如今我们来将项目导入到Eclipse中. 在将项目导入到Eclipse之前,确定你已经配置 ...

  5. struts2跳转类型解析

    struts 2 跳转类型 1.dispatcher  dispatcher 为默认跳转类型.用于返回一个视图资源 xml代码 : <result name="success" ...

  6. 【玩转微信公众平台六】 构建新浪SAEserver

    连接急于继续发言. ------本文主要介绍介绍如何设置 新浪SAEserver.猛戳 http://sae.sina.com.cn/1.先自己注冊一个账号,假设有新浪的账号,微博之类的都能够直接拿来 ...

  7. SQL 将URL编码转汉字!

    原文:SQL 将URL编码转汉字! -- ============================================= -- 作 者: ruijc -- 描 述: 将Url编码转明文字符 ...

  8. 一个IT学生的personal statement

    前一段时间的英语老师要求我们写一个自己的personal statement,我相信,作为一个IT学生,人很多personal statement应该都了如指掌.进一步的研究是必要的出国留学,当然,也 ...

  9. uva 1556 - Disk Tree(特里)

    题目连接:uva 1556 - Disk Tree 题目大意:给出N个文件夹关系,然后依照字典序输出整个文件文件夹. 解题思路:以每一个文件夹名作为字符建立一个字典树就可以,每一个节点的关系能够用ma ...

  10. Android:ViewPager详细解释(异步网络负载图片,有图片缓存,)并与导航点

    android 应用.准则欢迎页面. 和图像旋转木马特征, 或者没有很多其他的内容显示在一个页面.以被划分成多个页面,在这一刻viewpager这是非常容易使用. 首先看下效果: 以下是一个样例.带异 ...