wenbao与LCIS(最长公共上升子序列)

 

http://acm.hdu.edu.cn/showproblem.php?pid=5904

 

 

 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4 const int maxn = 1e6+10;
 5 const int maxn2 = 1e5+10;
 6 int sum1[maxn], sum2[maxn], c[maxn2], d[maxn2];
 7 int main(){
 8     int t, n, m, x;
 9     scanf("%d", &t);
10     while(t--){
11         int ma = 0;
12         scanf("%d %d", &n, &m);
13         for(int i = 0; i < n; i++){
14             scanf("%d", &c[i]);
15             sum1[c[i]] = sum1[c[i]-1] + 1;
16         }
17         for(int i = 0; i < m; i++){
18             scanf("%d", &d[i]);
19             sum2[d[i]] = sum2[d[i]-1] + 1;
20         }
21         for(int i = 0; i < n; i++) ma = max(ma, min(sum1[c[i]], sum2[c[i]]));
22         printf("%d\n", ma);
23         // memset(sum1, 0, sizeof(sum1));    //too young
24         // memset(sum2, 0, sizeof(sum2));    //too young
25         for(int i = 0; i < n; i++) sum1[c[i]] = 0;
26         for(int j = 0; j < m; j++) sum2[d[j]] = 0;
27     }
28     return 0;
29 }

 

 

 

 

 

只有不断学习才能进步!

 

posted @ 2018-04-14 13:47  wenbao  阅读(115)  评论(0编辑  收藏  举报