搜索专题【2009】四2.国王放置

 

 

var
    n,m,k,ans: integer;
    hash: array[0..4,0..4] of integer;

procedure work(x,y,tot:integer);
var i,j:integer;
begin
    if tot=k then begin inc(ans); exit; end;
    repeat
        while hash[x,y]<>0 do
        begin
            inc(y);
            if y=m then begin inc(x); y:=0; end;
            if x=n then exit;
        end;
        for i:=x-1 to x+1 do
            if(i>=0)and(i<n)then
                for j:=y-1 to y+1 do
                    if(j>=0)and(j<=m) then
                        inc(hash[x,y]);
        work(x,y,tot+1);
        for i:=x-1 to x+1 do
            if(i>=0)and(i<n)then
                for j:=y-1 to y+1 do
                    if(j>=0)and(j<=m) then
                        dec(hash[x,y]);
        inc(y);
        if y=m then begin inc(x); y:=0; end;
        if x=n then exit;
    until false;
end;

begin
    read(n,m,k);
    ans:=0;
    fillchar(hash,sizeof(hash),0);
    work(0,0,0);
    writeln(ans);
end. 

 

posted @ 2014-10-08 23:28  qilinart  阅读(237)  评论(0)    收藏  举报