Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大神求改 PASCAL

Posted by yangtianchen at 2013-10-10 15:12:13 on Problem 1159
var
  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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator