-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCRSCNTRY.cpp
More file actions
38 lines (36 loc) · 1014 Bytes
/
Copy pathCRSCNTRY.cpp
File metadata and controls
38 lines (36 loc) · 1014 Bytes
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
#include <iostream>
#include <vector>
using namespace std;
int LCS(vector <int> &A, vector <int> &B){
int i, j, lcs[A.size()+1][B.size()+1];
for(i=0; i<=A.size(); i++){
for(j=0; j<=B.size(); j++){
if(i==0 || j==0)
lcs[i][j]=0;
else if(A[i-1]==B[j-1])
lcs[i][j]=lcs[i-1][j-1]+1;
else
lcs[i][j]=max(lcs[i-1][j], lcs[i][j-1]);
}
}
return lcs[A.size()][B.size()];
}
int main(){
int t, n, d, i, max_length;
cin>>t;
while(t--){
vector <vector<int>> routes;
vector <int> v;
while(cin>>n && n!=0){
v.push_back(n);
while(cin>>d && d!=0)
v.push_back(d);
routes.push_back(v);
v.clear();
}
for(i=1, max_length=0; i<routes.size(); i++)
max_length=max(max_length, LCS(routes[0], routes[i]));
cout<<max_length<<"\n";
}
return 0;
}