forked from arv002-zz/spojcodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CRSCNTRY - Cross-country.cpp
66 lines (56 loc) · 1.13 KB
/
CRSCNTRY - Cross-country.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<bits/stdc++.h>
using namespace std;
int L[2][1005];
int LCS(int a[],int b[],int m, int n)
{
int i,j;
bool bi;
for(i=0; i<=m; i++)
{
bi=i&1;
for(j=0; j<=n; j++)
{
if(i==0||j==0)
L[bi][j]=0;
else if(a[i-1]==b[j-1])
L[bi][j]=L[1-bi][j-1]+1;
else
L[bi][j]=max(L[1-bi][j],L[bi][j-1]);
}
}
return L[bi][n];
}
int main()
{
int d;
cin>>d;
while(d--)
{
int a[1005],n,m,i;
for(i=0; i<1005; i++)
{
cin>>a[i];
n=i;
if(a[i]==0)
i=1005;
}
int t=1,Max=0;
while(1)
{
int T[1005],Q;
for(i=0; i<1005; i++)
{
cin>>T[i];
m=i;
if(T[i]==0)
i=1005;
}
if(T[0]==0)
break;
else
Q=LCS(a,T,n,m);
Max=max(Max,Q);
}
cout<<Max<<"\n";
}
}