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 |
的确可以纯动规做到n^2,0MSvar a,b:array[0..100]of longint; f,c,d:array[0..100,0..100]of longint; t,n,m,i,j:longint; function max(x,y:longint):longint; begin if x>y then exit(x) else exit(y); end; begin readln(t); repeat dec(t); readln(n,m); for i:=1 to n do read(a[i]); for i:=1 to m do read(b[i]); for i:=1 to n do for j:=1 to 100 do if a[i]=j then c[i,j]:=i else c[i,j]:=c[i-1,j]; for i:=1 to m do for j:=1 to 100 do if b[i]=j then d[i,j]:=i else d[i,j]:=d[i-1,j]; for i:=1 to n do for j:=1 to m do begin f[i,j]:=max(f[i-1,j],f[i,j-1]); if (a[i]<>b[j])and(c[i-1,b[j]]<>0)and(d[j-1,a[i]]<>0) then f[i,j]:=max(f[i,j],f[c[i-1,b[j]]-1,d[j-1,a[i]]-1]+2); end; writeln(f[n,m]); until t=0; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator