记录编号 80034 评测结果 AAAAAAAAAA
题目名称 交错匹配 最终得分 100
用户昵称 GravatarC语言入门 是否通过 通过
代码语言 Pascal 运行时间 0.822 s
提交时间 2013-11-06 18:10:04 内存使用 0.32 MiB
显示代码纯文本
program o;
var
n,m,i,j,i1,j1:longint;
up,down:array [0..200] of integer;
f:array [0..200,0..200] of longint;
function max(a,b:longint):longint;
begin
 if a>b then max:=a
        else max:=b;
end;
begin
assign (input,'crossa.in');
assign (output,'crossa.out');
reset (input);
rewrite (output);
 read (n,m);
 for i:=1 to n do
  read (up[i]);
 for j:=1 to m do
  read (down[j]);
 for i:=1 to n do
  for j:=1 to m do
    begin
     f[i,j]:=max(f[i,j],f[i-1,j]);
     f[i,j]:=max(f[i,j],f[i,j-1]);
     for i1:=j-1 downto 1 do
      for j1:=i-1 downto 1 do
       if (up[i]=down[i1])and(up[j1]=down[j])and(up[i]<>up[j1]) then
        f[i,j]:=max(f[i,j],f[j1-1,i1-1]+1);
    end;
 write (f[n,m]*2);
 close (input);
 close (output);
end.