N-longest Ordered subsequence POJ 2533 (Longest ascending subsequence)

Source: Internet
Author: User


N-longest Ordered subsequence
Time limit:2000ms Memory limit:65536kb 64bit IO format:%i64d &%i64u
Submit Status Practice POJ 2533

Description
A numeric sequence of AI is ordered if A1 < A2 < ... < an. Let the subsequence of the given numeric sequence (A1, A2, ..., an) is any sequence (AI1, AI2, ..., AiK), where 1 <= I1 < I2 < ... < IK <= N. For example, sequence (1, 7, 3, 5, 9, 4, 8) have ordered Subsequences, E. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences is of length 4, e. g., (1, 3, 5, 8).

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

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

#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <set > #include <map> #include <vector> #include <stack> #include <queue> #include <string># include<cstdlib> #include <cmath>//#include <bits/stdc++.h>using namespace Std;template<class T    >inline T Read (t&x) {char C;    while ((C=getchar ()) <=32) if (c==eof) return 0;    BOOL Ok=false;    if (c== '-') Ok=true,c=getchar ();    for (x=0; c>32; C=getchar ()) x=x*10+c-' 0 ';    if (OK) x=-x; return 1;} Template<class t> inline T read_ (t&x,t&y) {return read (x) &&read (y);} Template<class t> inline T read__ (t&x,t&y,t&z) {return read (x) &&read (y) &&read (z);}    Template<class t> inline void Write (T x) {if (x<0) Putchar ('-'), x=-x;    if (x<10) putchar (x+ ' 0 '); else write (X/10), Putchar (x%10+ ' 0 ');}    Template<class t>inline void Writeln (T x) {write (x); Putchar (' \ n ');} //-------ZCC IO Template------const int MAXN=1E4+10;CONST double inf=99999999; #define Lson (rt<<1), L,m#define Rson ( rt<<1|1), M+1,r#define M ((l+r) >>1) #define for (i,t,n) for (int i= (t);i< (n); i++) typedef long Long LL; typedef double DB;TYPEDEF pair<int,int> P; #define BUG printf ("---\ n"); #define MOD 10007int a[maxn];int dp[maxn];vo    ID solve () {int n;    scanf ("%d", &n);    Fill (Dp,dp+n,inf);    for (int i=0;i<n;i++) {scanf ("%d", &a[i]);    } for (int i=0;i<n;i++) {*lower_bound (Dp,dp+n,a[i]) =a[i]; } printf ("%d\n", Lower_bound (Dp,dp+n,inf)-DP);}    int main () {solve (); return 0;}


N-longest Ordered subsequence POJ 2533 (Longest ascending subsequence)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.