POJ 2533 longest Ordered subsequence maximum increment sequence

Source: Internet
Author: User

Description

A Numeric sequence ofAIis ordered ifA1<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

71 7 3 5 9 4 8

Sample Output

4

Source

Northeastern Europe 2002, Far-eastern subregion

To find the length of the longest increment sequence

Solving the puzzle: writing in another article

-------- http://www.cnblogs.com/Noevon/p/5685975.html

#include <stdio.h>intb[1010], a[1010];intMain () {intI, J, N, Max; scanf ("%d", &N);  for(i=1; i<=n;i++) scanf ("%d", &A[i]); a[0] =0;  for(i=1; i<=n;i++)    {         for(max=0, j=i;j>=0; j--)            if(a[i]>a[j]&&max<B[j]) Max=B[j]; B[i]= max+1; }     for(max=0, i=0; i<=n;i++)        if(Max <B[i]) Max=B[i]; printf ("%d\n", Max); return 0;}

POJ 2533 longest Ordered subsequence maximum increment sequence

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.