Question: option remember with Rook Polynomials

I am trying to write a program for calculating the number of ways to place k non-attacking rooks on an m x n board with restricted positions defined in B.  If i remove "option remember" the program works but it doesn't work very efficiently, and my goal is to extend this into three dimensions, so it needs to work fairly quickly in 2 dimensions.  The problem comes when I put in "option remember".  I know that maple is bringing back old values from C even though C has changed.  Is there a way to fix this while still using option remember?  Also, I am using Maple 11.

Rook := proc (A, m, n, B, k) local C, i, j, h, l, count; option remember;
count := 0;
  if k = 1 then
    for i from 1 to m do
      for j from 1 to n do
        if `not`(`in`([i, j], B)) then
          if add(A[p, j], p = 1 .. m) = 0 then
            if add(A[i, q], q = 1 .. n) = 0 then
              count := count+1
            end if
          end if
        end if
      end do
    end do
  else
    for i from 1 to m do
      for j from 1 to n do
        if `not`(`in`([i, j], B)) then
          if add(A[p, j], p = 1 .. m) = 0 then
            if add(A[i, q], q = 1 .. n) = 0 then
              for h from 1 to m do
                for l for 1 to n do
                  C[h, l] := A[h, l]
                end do
              end do;
              C[i, j] := 1;
              count := count+Rook(C, m, n, B, k-1);
              C[i, j] := 0
            end if
          end if
        end if
      end do
    end do
  end if;
count := count/k
end proc
 A2 := Array(1 .. 2, 1 .. 2);
for i from 1 to 2 do
  for j from 1 to 2 do
    A2[i, j] := 0
  end do
end do;
B1 := {[1, 1]};
Rook(A2, 2, 2, B1, 2)
 

Please Wait...