比赛 20090916练习赛 评测结果 WWWWWTTTTT
题目名称 字符串的距离 最终得分 0
用户昵称 .Xmz 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-09-16 21:10:08
显示代码纯文本
program xmz;
var
x,y:array[1..2000]of integer;
hx,hy,k,a,b,c,max:longint;
f:array[0..2000,0..2001]of longint;
t:char;
f1,f2:text;
begin
 assign(f1,'blast.in');assign(f2,'blast.out');
 reset(f1);rewrite(f2);
 repeat
  hx:=hx+1;
  read(f1,t);
  x[hx]:=ord(t)-96;
 until eoln(f1);
  readln(f1);a:=0;
 repeat
  hy:=hy+1;
  read(f1,t);
  y[hy]:=ord(t)-96;
 until eoln(f1);
  read(f1,k);

 for b:=1 to hy do
  f[1,b]:=abs(x[1]-y[b])+(b-1)*k;
  f[1,0]:=k;
  f[1,hy+1]:=(hy+1)*k;

 for a:=2 to hx-1 do
  for b:=0 to hy+1 do
   for c:=b to hy+1 do
    begin
    if c=0 then f[a,c]:=f[a-1,b]+k;
    if (c=hy+1)and((f[a,c]>f[a-1,b]+(c-b)*k)or(b=0)) then f[a,c]:=f[a-1,b]+(c-b)*k;
    if (c<>0)and(c<>hy+1) then
    if (f[a,c]>f[a-1,b]+abs(x[a]-y[c])+(c-b-1)*k)or(b=0)
     then f[a,c]:=f[a-1,b]+abs(x[a]-y[c])+(c-b-1)*k;
    end;
  a:=hx;
 for b:=0 to hy+1 do
  for c:=b to hy+1 do
   begin
    if c=0 then f[a,c]:=f[a-1,b]+k+k*hy;
    if (c=hy+1)and((f[a,c]>f[a-1,b]+(c-b)*k)or(b=0)) then f[a,c]:=f[a-1,b]+(c-b)*k;
    if ((c<>0)and(c<>hy+1)) then
    if (f[a,c]>f[a-1,b]+abs(x[a]-y[c])+(c-b-1)*k+(hy-c)*k)or(b=0)
     then f[a,c]:=f[a-1,b]+abs(x[a]-y[c])+(c-b-1)*k+(hy-c*k);
   end;

   max:=99999999;
 for a:=0 to hy+1 do
  if max>f[hx,a] then max:=f[hx,a];
 write(f2,max);
 close(f1);close(f2);
end.