Pagini recente » Cod sursa (job #724288) | Cod sursa (job #1242197) | Cod sursa (job #2479010) | Cod sursa (job #1420412) | Cod sursa (job #150856)
Cod sursa(job #150856)
var a,b,d:array[1..1024] of longint;
c:array[0..1024,0..1024] of longint;
n,i,j,k,l:longint;
function max(x,y:longint):longint;
begin
if x>y then max:=x
else max:=y;
end;
begin
assign(input,'cmlsc.in');reset(input);
reset(output);
assign(output,'cmlsc.out');
read(m);
read(N);
for i:=1 to m do read(a[i]);
for i:=1 to n do read(b[i]);
for i:=1 to m do
for j:=1 to n 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]);
for i:=1 to n do
maxi:=max(maxi,a[m,i]);
for i:=m downto 1 do
for j:=1 to n do
if c[i][j]=max then
begin
inc(K);
d[k]:=a[i];
dec(max);
break;
end;
writeln(K);
for i:=k downto 1 do write(d[i],' ');
close(input);
close(output);
end.