POJ 2533 Longest Ordered subsequence "maximum increment subsequence" "DP thought"

Source: Internet
Author: User

Longest Ordered subsequence time limit:4000/2000ms (java/other) Memory limit:131072/65536k (java/other) Total Submiss Ion (s): 6 Accepted Submission (s): 1Problem Descriptiona Numeric sequence of AIis 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.
Inputthe 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
Outputoutput 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

Sourcepku



The AI{A1,A2,......, AI}, which requires a sequence of length I, is the longest incrementing subsequence of the sequence ai-1{a1,a2,......, ai-1}, with each element (A1,a2,......, ai-1) as the longest increment sequence of the largest element, and then compares all those ascending sequences to AI. If a length of the end of the m sequence of elements AJ (j<i) is smaller than the AI, then the element AI is added to the increment subsequence, a new sequence of length m+1 is obtained, otherwise its length is not changed, and the length of all I sequences processed is compared, and the longest sequence is the longest increment subsequence to be obtained.


The idea of this algorithm is very simple, if we want to get the longest increment subsequence of AI sequence, we need to calculate the longest increment sub-sequence of all the elements of ai-1, and then push forward the ai-2,ai-3,, turn this process upside down, we can obtain the algorithm, and then launch A1,a2,a3, Until the AI is launched.

Translate: Give a number n input n number to find the longest increment subsequence of this n number
When i=5 with 1 7 3 5 9 4 is the last number, each eldest son sequence is: 11 71 31 3 5 1 3 5 91 3 4
I=6, added the number 8 sequence is: 1 Bayi 7 Bayi 3 Bayi 3 5 Bayi 3 5 9 X1 3 4 8 so 4 is max length and more than one
Standard lis longest increment subsequence notation #include<stdio.h> #include <string.h>int main (void) {int n;    int a[10100],liss[10100];        while (~SCANF ("%d", &n)) {for (int i=0;i<n;i++) {scanf ("%d", &a[i]);        } int max=0;        18-19 Direct liss[] All brush to 1 correct for (int i=0;i<n;i++) liss[i]=1; for (int i=1;i<n;i++) {for (int j=0;j<i;j++) {if (a[i]>a[j]&&l                Iss[j]+1>liss[i]) {liss[i]=liss[j]+1;            }} if (Max<liss[i]) {max=liss[i];    }} printf ("%d\n", Max); } return 0;}    WA notation #include<stdio.h> #include <string.h>int main (void) {int n;    int a[10100],liss[10100];        while (~SCANF ("%d", &n)) {for (int i=0;i<n;i++) {scanf ("%d", &a[i]); }/* 65-69 line This is wrong wa many times because it can't change every time.Liss[0] to be the correct value or to write liss[0] into the for loop but the initial I of the loop is changed to 0 is also correct */liss[0]=1;        int max=0;            for (int i=1;i<n;i++)//Note the cyclic initial value of I is 1 {liss[i]=1;                    for (int j=0;j<i;j++) {if (A[i]>a[j]&&liss[j]+1>liss[i]) {                liss[i]=liss[j]+1;            }} if (Max<liss[i]) {max=liss[i];    }} printf ("%d\n", Max); } return 0;}


POJ 2533 Longest Ordered subsequence "maximum increment subsequence" "DP thought"

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.