Longest Ordered Subsequence POJ - 2533 (最长有序子序列)

原创 2018年04月15日 18:14:23
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 59701 Accepted: 26753

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

题目:给n个数,找出那个数中最长的上升子序列;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;

const int maxn = 1e5+7;
int n, s[maxn], dp[maxn];


/*
if(s[j] > s[i]) dp[j] = max(dp[j] , dp[i] + 1);
*/

int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
            scanf("%d", &s[i]);
            dp[i] = 1;
    }
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(s[j] > s[i]) dp[j] = max(dp[j], dp[i] + 1);
        }
    }
    int maxl = 0;
    for(int i = 0; i < n; i++)
        maxl =max(maxl, dp[i]);
    cout << maxl << endl;
    return 0;
}


版权声明: https://blog.csdn.net/weixin_39792252/article/details/79951475

时间序列(R语言处理金融序列)

使用R语言处理金融时间序列。 课程为零基础入门课程,旨在通过该课程能够了解基本的时间序列。
  • 2017年06月27日 20:13

N - Longest Ordered Subsequence——POJ 最长递增子序列

N - Longest Ordered Subsequence Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64...
  • chudongfang2015
  • chudongfang2015
  • 2016-05-19 10:47:44
  • 429

LeetCode-594. Longest Harmonious Subsequence (JAVA)最长和谐子序列

LeetCode-594. Longest Harmonious Subsequence (JAVA)最长和谐子序列
  • mine_song
  • mine_song
  • 2017-05-25 21:46:41
  • 1074

POJ Problem 2533 Longest Ordered Subsequenc

求最长递增子序列的长度 动态规划法,算法复杂度为O(nlogn) #include #include #include #include using namespace std; int m...
  • linian8123654
  • linian8123654
  • 2016-11-06 15:38:05
  • 88

leetcode 300. Longest Increasing Subsequence-最长子序列|动态规划

原题链接:300. Longest Increasing Subsequence 【思路1-Java】T=O(n2)|M=O(n) 建立一个大小与 nums 长度相等的数组 maxLens,用于记录每...
  • happyaaaaaaaaaaa
  • happyaaaaaaaaaaa
  • 2016-06-02 20:17:05
  • 959

leetcode(300)—— Longest Increasing Subsequence(最长递增子序列)

参考 Python 解法: 动态规划 —— 最长递增子序列(LIS) 原题位置:Longest Increasing Subsequence | LeetCode OJ题目的说明: 严格递增; 子序列...
  • lanchunhui
  • lanchunhui
  • 2016-06-08 11:33:06
  • 1336

Pku acm 第2533题 Longest Ordered Subsequence 代码,有详细的注释

  • 2008年01月01日 20:09
  • 549B
  • 下载

TOJ 3601.Longest Contiguous Subsequence 最长连续公共子序列

最长连续公共子序列问题最长连续公共子序列,和公共子序列不一样。这里要求子序列连续,相对而言要简单一些。算法设计思路是动态规划(虽然我感觉和动态规划的感觉不怎么相对)。假设两个序列s1[m]和s2[n]...
  • DWLVXW0325
  • DWLVXW0325
  • 2016-07-03 23:04:20
  • 534

POJ 2533 最长上升子序列

Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissi...
  • qq_37943488
  • qq_37943488
  • 2017-08-15 16:02:56
  • 69

HOJ 10027 Longest Ordered Subsequence Extention

Longest Ordered Subsequence Extention Time Limit: 1000ms, Special Time Limit:2500ms, Memory Lim...
  • u013595779
  • u013595779
  • 2014-04-16 17:14:38
  • 823
收藏助手
不良信息举报
您举报文章:Longest Ordered Subsequence POJ - 2533 (最长有序子序列)
举报原因:
原因补充:

(最多只允许输入30个字)