-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCROSS_COUNTRY.cpp
More file actions
58 lines (57 loc) · 943 Bytes
/
CROSS_COUNTRY.cpp
File metadata and controls
58 lines (57 loc) · 943 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<stdio.h>
int main()
{
int t, alen, tlen, temp, max, i, j;
char ar[2001][2001];
int tom[2001];
int agnes[2001];
scanf("%d", &t);
while(t--)
{
temp=1;
alen=0;
while(temp!=0)
{
scanf("%d", &temp);
agnes[alen]=temp;
alen++;
}
max=0;
while(1)
{
scanf("%d", &temp);
if(temp==0)
break;
else
{
tlen=1;
tom[0]=temp;
while(temp!=0)
{
scanf("%d", &temp);
tom[tlen]=temp;
tlen++;
}
//input taken
for(i=0;i<alen;i++)
ar[i][0]='0';
for(j=1;j<tlen;j++)
ar[0][j]='0';
for(i=1;i<alen;i++)
for(j=1;j<tlen;j++)
{
if(ar[i-1][j]>ar[i][j-1])
ar[i][j] = ar[i-1][j];
else
ar[i][j] = ar[i][j-1];
if((tom[j-1]==agnes[i-1])&&(ar[i-1][j-1]+1>ar[i][j]))
ar[i][j] = ar[i-1][j-1] + 1;
}
if(max<ar[alen-1][tlen-1])
max = ar[alen-1][tlen-1];
}
}
printf("%d\n", max-'0');
}
return 0;
}