Ultraviolet A 111-history grading

Source: Internet
Author: User

Question: there have been some historical incidents in sequence. Now many students have written different order tables,

Determine the maximum sequence of the students in the correct order.

Analysis: DP, Lis, maximum ascending subsequence.

Note the data format of this question. Each element in the string corresponds to the position of the event corresponding to the subscript number in the table;

State: F (n) records the longest ascending subsequence of the sequence with the nth element as the ending element. There is a transfer equation:

F (n) = max (f (I) + 1) {0 <I <n and data [I] <data [N]}.

Note: I found many DP questions (⊙ _ ⊙ ).

# Include <iostream> # include <cstdlib> using namespace STD; int A [22], B [22], L [22]; int main () {int N, T; cin> N; For (INT I = 1; I <= N; ++ I) CIN> A [I]; while (CIN> T) {B [T] = 1; for (INT I = 2; I <= N; ++ I) {CIN> T; B [T] = I ;} for (INT I = 1; I <= N; ++ I) {L [I] = 1; for (Int J = 1; j <I; ++ J) if (A [B [J] <A [B [I] & L [J]> = L [I]) L [I] = L [J] + 1;} int max = 0; For (INT I = 1; I <= N; ++ I) if (max <L [I]) max = L [I]; cout <max <Endl;} return 0 ;}

Ultraviolet A 111-history grading

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.