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

的确可以纯动规做到n^2,0MS

Posted by lydliyudong at 2011-04-22 13:04:38 on Problem 1692
var
 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:
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