// Va problem 111-history grading // verdict: accepted // submission date: 2011-11-25 // ultraviolet Run Time: 0.052 S // copyright (c) qiu, 2011. Metaphysis # Yeah dot net // [solution] // you can convert the problem to the problem of the longest ascending subsequence. # Include <iostream> # include <sstream> using namespace STD; # define maxn 25int order [maxn], events [maxn], length [maxn], n; int getscores (void) {for (INT I = 1; I <= N; I ++) length [I] = 1; for (INT I = 1; I <= N; I ++) for (Int J = 1; j <I; j ++) if (events [J] <events [I] & (length [J] + 1)> length [I]) length [I] = length [J] + 1; int maxlength = 1; for (INT I = 1; I <= N; I ++) maxlength = max (maxlength, length [I]); Return maxlength;} int getindex (INT index) {for (INT I = 1; I <= N; I ++) if (Order [I] = index) return I;} int main (INT argc, char const * argv []) {string line; int index; CIN> N; for (INT I = 1; I <= N; I ++) {CIN> index; Order [Index] = I;} cin. ignore (); While (Getline (CIN, line) {istringstream ISS (line); For (INT I = 1; I <= N; I ++) {ISS> index; events [Index] = getindex (I) ;}cout <getscores () <Endl ;}return 0 ;}