比赛 |
noip_6 |
评测结果 |
ATTTTWWTTT |
题目名称 |
回文词 |
最终得分 |
10 |
用户昵称 |
Achilles |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-10-08 21:33:11 |
显示代码纯文本
program palin;
const
jx=5000;
var
a,b,s:array[1..jx]of char;
max:array[0..jx,0..jx]of integer;
n,i,j1,j2,maxs:integer;
begin
assign(input,'palin.in');
assign(output,'palin.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
read(s[i]);
fillchar(max,sizeof(max),0);
max[1,1]:=1;
maxs:=0;
for i:=0 to n do
begin
for j1:=1 to i do
a[j1]:=s[i+1-j1];
for j1:=i+1 to n do
b[j1-i]:=s[j1];
for j1:=1 to i do
for j2:=j1 to n-i+1 do
begin
if a[j1]=b[j2] then max[j1,j2]:=max[j1-1,j2-1]+1
else if max[j1-1,j2-1]>max[j1,j2] then max[j1,j2]:=max[j1-1,j2-1];
end;
if (n<>0)and(a[1]<>b[1]) then begin
if max[i,n-i+1]*2+1>maxs then maxs:=max[i,n-i+1]*2+1;
end
else begin
if max[i,n-i+1]*2>maxs then maxs:=max[i,n-i+1]*2;
end;
end;
writeln(n-maxs);
close(input);
close(output);
end.