比赛 |
20120703 |
评测结果 |
AAATWTTTTT |
题目名称 |
DNA重组 |
最终得分 |
30 |
用户昵称 |
zhangchi |
运行时间 |
6.724 s |
代码语言 |
Pascal |
内存使用 |
34.52 MiB |
提交时间 |
2012-07-03 11:43:36 |
显示代码纯文本
var
i,j,k,o,len1,len2,mark,t,ans:longint;
s1,s2:ansistring;
dp:array[0..3000,0..3000] of longint;
begin
assign(input,'dna.in'); reset(input);
assign(output,'dna.out'); rewrite(output);
readln(t);
for o:=1 to t do
begin
fillchar(dp,sizeof(dp),$7F div 2);
dp[0,0]:=0;
for i:=1 to 3000 do
dp[0,i]:=1;
readln(s1);
readln(s2);
len1:=length(s1);
len2:=length(s2);
for i:=1 to len2 do
for j:=i to len1 do
if s1[j]=s2[i] then
begin
dp[i,j]:=dp[i-1,j-1];
for k:=i-1 to j-2 do
if dp[i-1,k]+3<dp[i,j] then
dp[i,j]:=dp[i-1,k]+3;
end;
ans:=maxlongint;
mark:=1;
for i:=len2 to len1 do
if ans>dp[len2,i] then
begin
ans:=dp[len2,i];
if i=len1 then dec(mark);
end;
if ans>100000000 then writeln(-1) else writeln(ans+mark);
end;
close(input); close(output);
end.