题意
设有A、B两个字符串,找出A、B共同子串,每个字符串无相同字符,可以不连续,但顺序不能颠倒。
分析
if s1[i]=s2[j] then f[i,j]:=f[i-1,j-1]+1 else f[i,j]:=max(f[i-1,j],f[i,j-1]);
var
s1,s2:string;
l1,l2,i,j:longint;
f:array[0..300,0..300]of longint;
function max(x,y:longint):longint;
begin
if x>y then exit(x) else exit(y);
end;
begin
readln(s1);
readln(s2);
l1:=length(s1);
l2:=length(s2);
fillchar(f,sizeof(f),0);
for i:=1 to l1 do
for j:=1 to l2 do
begin
if s1[i]=s2[j] then f[i,j]:=f[i-1,j-1]+1 else f[i,j]:=max(f[i-1,j],f[i,j-1]);
end;
write(f[l1,l2]);
end.