UVa OJ 10405-Longest Common Subsequence

    技术2022-11-07  29

     

    动归水题:

    { Author:wzx961008 Problem:UVa 10405-Longest Common Subsequence Verdict:Accepted Language:PASCAL Run Time:0.096s Submission Date:2011-01-16 08:47:29 } uses math; var s1,s2:ansistring; l1,l2,i,j:longint; f:array[0..1000,0..1000]of longint; begin while not eof do begin readln(s1); readln(s2); l1:=length(s1); l2:=length(s2); fillchar(f,sizeof(f),0); for i:=2 to l1+1 do for j:=2 to l2+1 do begin f[i,j]:=max(f[i-1,j],f[i,j-1]); if s1[i-1]=s2[j-1] then f[i,j]:=max(f[i,j],f[i-1,j-1]+1); end; writeln(f[l1+1,l2+1]); end; end. 

     

    最新回复(0)