-
Notifications
You must be signed in to change notification settings - Fork 0
/
CRSCNTRY.cpp
74 lines (64 loc) · 1.61 KB
/
CRSCNTRY.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
67
68
69
70
71
72
73
74
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int
//-4%3=-1
int main() {
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lld t;
cin>>t;
while(t--)
{
vector <int> res;
int n=1;
while(n!=0)
{
cin>>n;
res.push_back(n);
}
int ans=0;
n=1;
while(1)
{
vector <int> temp;
int a=1;
while(a!=0)
{
cin>>a;
temp.push_back(a);
}
if(temp[0]==0)
break;
int m=res.size(),n=temp.size();
int dp[m+1][n+1];
memset(dp,-1,sizeof(dp));
/*for(int i=0;i<temp.size();i++)
cout<<temp[i]<<" ";
cout<<"\n";*/
for(int i=0;i<=m;i++)
{
for(int j=0;j<=n;j++)
{
if(i==0||j==0)
dp[i][j]==0;
else if(res[i-1]==temp[j-1])
dp[i][j]=1+dp[i-1][j-1];
else
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
/*for(int i=0;i<=m;i++)
{
for(int j=0;j<=n;j++)
cout<<dp[i][j]<<" ";
cout<<"\n";
}*/
ans=max(ans,dp[m][n]);
}
cout<<ans<<"\n";
}
}