| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
真是ft到家了,今天某人问我这题,我把我以前ac的程序又交了一边,发现TLE......const
maxn=5000;
var
a:array[1..maxn] of char;
f1,f2:array[0..maxn] of longint;
i,j,k,l,m,n,t,s:longint;
function max(a,b:longint):longint;
begin
if a>b then max:=a else max:=b;
end;
begin
readln(n);
for i:=1 to n do
read(a[i]);
readln;
fillchar(f1,sizeof(f1),0);
fillchar(f2,sizeof(f2),0);
for i:=1 to n do begin
for j:=1 to n do
if a[i]=a[n-j+1] then f2[j]:=f1[j-1]+1 else
f2[j]:=max(f2[j-1],f1[j]);
f1:=f2;
end;
writeln(n-f2[n]);
end.
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator