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

Re:PASCAL的AC程序(有注解)

Posted by lqj679ssn at 2012-08-05 14:55:26 on Problem 1159
In Reply To:PASCAL的AC程序(有注解) Posted by:lqj679ssn at 2012-08-05 14:53:28
> function max(x,y:longint):longint;
>   begin
>     if x>y then exit(x)
>            else exit(y)
>   end;
> var
>   n,i,j,t,p:longint;
>   s1,s2:array[0..5000] of char;
>   f:array[0..5000,0..5000] of integer;
> begin
>   readln(n);
>   for i:=1 to n do //s2是s1的倒串
>   begin
>     read(s1[i]);
>     s2[n-i+1]:=s1[i];
>   end;
> 
>   for i:=1 to n do//找最长公共子序列
>     for j:=1 to n do
>     begin
>       f[i,j]:=max(f[i-1,j],f[i,j-1]);
>       if s1[i]=s2[j] then f[i,j]:=max(f[i,j],f[i-1,j-1]+1);
>     end;
> 
>   writeln(n-f[n,n]);//ANSWER=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