//GCIS
1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "algorithm" 5 using namespace std; 6 int dp[510], Max; 7 int s1[510], s2[510]; 8 int len1, len2; 9 10 int main() 11 { 12 int T, i, j; 13 scanf("%d", &T); 14 while(T--) { 15 scanf("%d", &len1); 16 for(i = 1; i <= len1; ++i) 17 scanf("%d", &s1[i]); 18 scanf("%d", &len2); 19 for(i = 1; i <= len2; ++i) 20 scanf("%d", &s2[i]); 21 memset(dp, 0, sizeof(dp)); 22 for(i = 1; i <= len1; ++i) { 23 Max = 0; 24 for(j = 1; j <= len2; ++j) { 25 if(s1[i] > s2[j]) 26 Max = max(Max, dp[j]); 27 else if(s1[i] == s2[j]) 28 dp[j] = max(dp[j], Max + 1); 29 } 30 } 31 int res = 0; 32 for(i = 1; i <= len2; ++i) { 33 res = max(res, dp[i]); 34 } 35 printf("%d\n", res); 36 if(T) 37 printf("\n"); 38 } 39 }
时间: 2024-09-29 22:08:03