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 |
Re:PASCAL的AC程序(有注解)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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator