比赛 |
20090916练习赛 |
评测结果 |
AAAAAAAAAA |
题目名称 |
字符串的距离 |
最终得分 |
100 |
用户昵称 |
belong.zmx |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-09-21 19:12:29 |
显示代码纯文本
program blast(input,output);
var
dp:array[0..2000,0..2000]of longint;
ch1,ch2:array[1..2000]of char;
k,l,p:longint;
i,j:longint;
ch:char;
begin
assign(input,'blast.in');
reset(input);
repeat
read(ch);
if ord(ch)=13 then break
else
begin
inc(k);
ch1[k]:=ch;
end;
until ch='';
readln;
repeat
read(ch);
if ord(ch)=13 then break
else
begin
inc(l);
ch2[l]:=ch;
end;
until ch='';
readln(p);
close(input);
for i:=1 to k do
dp[i,0]:=dp[i-1,0]+p;
for j:=1 to l do
dp[0,j]:=dp[0,j-1]+p;
for i:=1 to k do
for j:=1 to l do
begin
dp[i,j]:=dp[i-1,j-1]+abs(ord(ch1[i])-ord(ch2[j]));
if dp[i-1,j]+p<dp[i,j] then dp[i,j]:=dp[i-1,j]+p;
if dp[i,j-1]+p<dp[i,j] then dp[i,j]:=dp[i,j-1]+p;
end;
assign(output,'blast.out');
rewrite(output);
writeln(dp[k,l]);
close(output);
end.