Pagini recente » Cod sursa (job #2220534) | Cod sursa (job #2978621) | Cod sursa (job #1359436) | Cod sursa (job #1254108) | Cod sursa (job #520353)
Cod sursa(job #520353)
var a,b:array[1..1024] of integer;
c:array[0..1024,0..1024] of integer;
n,m,i,j:integer;
function max(x,y:byte):byte;
begin
if x>y then max:=x else max:=y;
end;
procedure afisare(x,y:byte);
begin
while a[x]<>b[y] do
if c[x-1,y]>c[x,y-1] then dec(x) else dec(y);
if c[x-1,y-1]<>0 then afisare(x-1,y-1);
write(a[x],' ');
end;
begin
assign(input,'cmlsc.in');reset(input);
assign(output,'cmlsc.out');rewrite(output);
readln(n,m);
for i:=1 to n do read(a[i]);
for i:=1 to m do read(b[i]);
for i:=1 to n do
for j:=1 to m do
if a[i]=b[j] then c[i,j]:=c[i-1,j-1]+1
else c[i,j]:=max(c[i-1,j],c[i,j-1]);
writeln(c[n,m]);
afisare(n,m);
end.