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 |
大神求改 PASCALvar len,n,i,j:longint; t:char; dp:array[0..5001,0..5001]of shortint; b,a:array[0..5001]of char; begin readln(n); for i:=1 to n do begin read(t); a[i]:=t; b[n-i+1]:=t; end; for i:=0 to n do begin dp[i,0]:=0; dp[0,i]:=0; end; for i:=1 to n do for j:=1 to n do begin if dp[i,j-1]>dp[i-1,j] then dp[i,j]:=dp[i,j-1] else dp[i ,j]:=dp[i-1,j]; if a[i]=b[j] then if dp[i-1][j-1]+1>dp[i,j] then dp[i,j]:=dp[i-1,j-1]+1; end; len:=dp[n,n]; writeln(n-len); end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator