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