-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCRSCNTRY.c
54 lines (52 loc) · 920 Bytes
/
CRSCNTRY.c
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
#include<bits/stdc++.h>
using namespace std;
#define MAX 2005
int gs;
int ts;
int dps[MAX][MAX];
int girl[MAX];
int tom[MAX];
int funk(int i, int j)
{
if(i >= gs || j >= ts) return 0;
if(dps[i][j] != -1) return dps[i][j];
if(girl[i] == tom[j])
return dps[i][j] = 1+funk(i+1,j+1);
return dps[i][j] = max(dps[i][j+1] = funk(i,j+1), dps[i+1][j] = funk(i+1,j));
}
int main()
{
int t;
cin>>t;
int i;
int mval;
while(t--)
{
i = 0;
mval = INT_MIN;
while(true)
{
cin>>girl[i++];
if(girl[i-1] == 0) break;
}
gs = i-1;
while(true)
{
i=0;
cin>>tom[i];
if(tom[i] == 0) break;
i++;
while(true)
{
cin>>tom[i++];
if(tom[i-1] == 0) break;
}
ts = i-1;
memset(dps,-1,sizeof(dps));
int fk = funk(0,0);
//cout<<"fk="<<fk<<endl;
mval=max(mval,fk);
}
cout<<mval<<endl;
}
}