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

Re:这题cdq大神的插头dp论文里面讲的太详细了,对着写就ok了

Posted by williamljb at 2010-08-20 11:22:49 on Problem 1739
In Reply To:这题cdq大神的插头dp论文里面讲的太详细了,对着写就ok了 Posted by:ccsu2008021220 at 2010-08-13 16:55:46
> rt!
真的可以吗,我怎么tle了:
{$inline on}
program pku1739;
const
  p:array[-1..10]of longint=(1,1,3,9,27,81,243,729,2187,6561,19683,59049);
var
  i,j,k,n,m:longint;
  f:array[0..10,0..10,0..59049]of longint;
  q:array[0..59049,1..9]of longint;
  g:array[1..8,1..8]of longint;
  ch:char;
  s:array[1..9]of longint;
procedure doit(x:longint);inline;
  var
    t,i,j,xx:longint;
  begin
    t:=0;j:=0;xx:=x;
    while x>0 do
      begin
        i:=x mod 3;
        inc(j);
        if i=2
          then begin
            inc(t);
            s[t]:=j;
          end;
        if i=1
          then begin
            if t=0 then exit;
            q[xx,j]:=s[t];
            q[xx,s[t]]:=j;
            dec(t);
          end;
        x:=x div 3;
      end;
  end;
procedure solve(x,y,z:longint);inline;
  var
    x1,x2,x3,x4,zz,j:longint;
  begin
    if f[x,y,z]=0 then exit;
    zz:=z;
    x1:=z div p[m+1-y]*p[m+1-y];
    z:=z mod p[m+1-y];
    x4:=z mod p[m+1-y-2];
    z:=z div  p[m+1-y-2];
    x3:=z mod 3;
    x2:=z div 3;
    inc(x1,x4);
    z:=zz;
    case g[x,y+1]of
      0:begin
          if(x2=0)and(x3=0)
            then inc(f[x,y+1,x1+p[m+1-y-1]+p[m+1-y-2]*2],f[x,y,z]);
          if(x2+x3=3)and(q[z,m+1-y-1]<>m+1-y)
            then inc(f[x,y+1,x1],f[x,y,z]);
          if(x2+x3=1)and(x2*x3=0)
            then begin
              inc(f[x,y+1,x1+p[m+1-y-1]],f[x,y,z]);
              inc(f[x,y+1,x1+p[m+1-y-2]],f[x,y,z]);
            end;
          if(x2+x3=2)and(x2*x3=0)
            then begin
              inc(f[x,y+1,x1+p[m+1-y-1]*2],f[x,y,z]);
              inc(f[x,y+1,x1+p[m+1-y-2]*2],f[x,y,z]);
            end;
          if(x2=1)and(x3=1)
            then begin
              j:=p[q[z,m+1-y-1]-1];
              inc(f[x,y+1,x1-j],f[x,y,z]);
            end;
          if(x2=2)and(x3=2)
            then begin
              j:=p[q[z,m+1-y]-1];
              inc(f[x,y+1,x1+j],f[x,y,z]);
            end;
        end;
      1:if(x2=0)and(x3=0)
          then inc(f[x,y+1,x1],f[x,y,z]);
      2:begin
          if(x2+x3=1)and(x2*x3=0)
            then begin
              inc(f[x,y+1,x1+p[m+1-y-1]],f[x,y,z]);
              inc(f[x,y+1,x1+p[m+1-y-2]],f[x,y,z]);
            end;
          if(x2+x3=2)and(x2*x3=0)
            then begin
              inc(f[x,y+1,x1+p[m+1-y-1]*2],f[x,y,z]);
              inc(f[x,y+1,x1+p[m+1-y-2]*2],f[x,y,z]);
            end;
          if x2+x3=0
            then inc(f[x,y+1,x1+p[m+1-y-1]+p[m+1-y-2]*2],f[x,y,z]);
        end;
    end;
  end;
begin
  readln(n,m);
  for i:=0 to p[9]-1 do
    doit(i);
  while n<>0 do
    begin
      fillchar(f,sizeof(f),0);
      f[1,0,0]:=1;
      for i:=1 to n do
        begin
          for j:=1 to m do
            begin
              read(ch);
              if ch='.'
                then g[i,j]:=0
                else g[i,j]:=1;
            end;
          readln;
        end;
      g[n,1]:=2;g[n,m]:=2;
      for i:=1 to n do
        begin
          for j:=0 to m-1 do
            for k:=0 to p[m+1]-1 do
              solve(i,j,k);
          for k:=1 to p[m+1]-1 do
            if k mod 3=0
              then f[i+1,0,k div 3]:=f[i,m,k];
        end;
      writeln(f[n,m,p[m]+2]);
      readln(n,m);
    end;
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