vj1327 回文词

vj1327...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: const maxn=5000; var n:integer; a:array[0..maxn] of char; f:array[0..maxn,0..maxn] of integer; function min(x,y:integer):integer; begin if x<=y then exit(x) else exit(y); end; procedure init; var i:integer; begin readln(n); for i:=1 to n do read(a[i]); end; procedure main; var l,i:integer; begin for l:=2 to n do for i:=1 to n-l+1 do if a[i]=a[i+l-1] then f[i,i+l-1]:=f[i+1,i+l-2] else f[i,i+l-1]:=min(f[i+1,i+l-1],f[i,i+l-2])+1; end; procedure print; begin writeln(f[1,n]); end; begin init; main; print; end. ...
View Full Document

Ask a homework question - tutors are online