比赛 20120703 评测结果 AWWWWWWWWW
题目名称 DNA重组 最终得分 10
用户昵称 fuhao 运行时间 0.773 s
代码语言 Pascal 内存使用 0.19 MiB
提交时间 2012-07-03 11:58:18
显示代码纯文本
const maxn=3001;
var
 i,t:longint; s1,s2:ansistring;
 x,y:array[0..maxn] of char; f1,f2:array[0..maxn] of longint;
 procedure dp;
 var i,j:longint;
 begin
  for i:=1 to length(s1) do x[i]:=s1[i];
  for i:=1 to length(s2) do y[i]:=s2[i];
  for i:=1 to length(s1) do f1[i]:=1;
  x[0]:=' '; y[0]:=' '; f1[0]:=0;
  for i:=1 to length(s2) do
  begin
   for j:=0 to length(s1) do f2[j]:=maxlongint;
   for j:=i to length(s1) do
    if y[i]=x[j] then
     if f1[j-1]<>maxlongint then
      if y[i-1]=x[j-1] then
       f2[j]:=f1[j-1]
      else f2[j]:=f1[j-1]+1
     else
    else
    if f2[j-1]<>maxlongint then
     if y[i]<>x[j-1] then
      f2[j]:=f2[j-1] else f2[j]:=f2[j-1]+1;
   f1:=f2;
  end;
  if f2[length(s1)]<>maxlongint then
   writeln(f2[length(s1)]) else writeln(-1);
 end;
begin
 assign(input,'dna.in'); reset(input);
 assign(output,'dna.out'); rewrite(output);
 readln(t);
 for i:=1 to t do
  begin
   readln(s1);
   readln(s2);
   dp;
  end;
 close(input); close(output);
end.