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:为什么会过不了呢?所有的数据都对呀。(附带code)In Reply To:为什么会过不了呢?所有的数据都对呀。(附带code) Posted by:RUNSLOWLY at 2008-09-27 14:30:16 这是我的代码,用P写的,一样,而且明显的O(行数×字符串1长度×字符串2长度),居然还TLE? 用的动规算法。 var i,j,k:integer; n,m:longint; str1,str2:array[0..2000] of char; str1len,str2len:longint; ch:char; f:array[0..2000,0..2000] of integer; procedure dynamic; var i,j,k:longint; begin for i:=0 to n do begin for j:=0 to m do begin f[i,j]:=0; end; end; for i:=1 to n do begin for j:=1 to m do begin if str1[i]=str2[j] then begin f[i,j]:=f[i-1,j-1]+1; end else begin if f[i-1,j]>=f[i,j-1] then begin f[i,j]:=f[i-1,j]; end else begin f[i,j]:=f[i,j-1]; end; end; end; end; end; begin while not eof do begin str1len:=0; str2len:=0; read(ch); str1len:=0; while ch<>' ' do begin inc(str1len); str1[str1len]:=ch; read(ch); end; while ch=' ' do begin read(ch); end; while not eoln do begin inc(str2len); str2[str2len]:=ch; read(ch); end; inc(str2len); str2[str2len]:=ch; n:=str1len; m:=str2len; dynamic; writeln(f[n,m]); end; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator