Question: Give a maximum of five sequences and ask how long the longest common subsequences of these sequences are.
Solution: brain pumping level I am, the first sequence of each number position is fixed, so as long as the maintenance of a K-1 dimension of the ordering Set. Then, when each location is valid
The longest ascending subsequence is enough.
1 # include <bits/stdc ++. h>
2 using namespace STD;
3 const int INF = 0x3f3f3f;
4 const int max = 1000 + 10;
5 int A [Max], X;
6 int DP [Max];
7 int L [10] [Max];
8 int main (){
9 int N, K;
10 while (scanf ("% d", & N, & K) = 2 ){
11 For (INT I = 1; I <= N; I ++ ){
12 scanf ("% d", & A [I]);
13}
14 For (INT I = 1; I <K; I ++ ){
15 For (Int J = 1; j <= N; j ++ ){
16 scanf ("% d", & X );
17 L [I] [x] = J;
18}
19}
20 memset (DP,-1, sizeof (DP ));
21 bool flag;
22 For (INT I = 1; I <= N; I ++ ){
23 DP [I] = 1;
24 For (Int J = 1; j <I; j ++ ){
25 flag = true;
26 For (int m = 1; m <K; m ++ ){
27 if (L [m] [A [I] <L [m] [A [J]) Flag = false;
28}
29 If (FLAG) DP [I] = max (DP [I], DP [J] + 1 );
30}
31}
32 int ans =-INF;
33 for (INT I = 1; I <= N; I ++) ans = max (ANS, DP [I]);
34 printf ("% d \ n", ANS );
35}
36 return 0;
37}
Codeforces round #264 (Div. 2) d