poj1321棋盘问题{wa}
2013-11-04 21:45
253 查看
var
n,k,i,j,ans:longint;
vx,vy:array[1..8] of boolean;
map:array[1..8,1..8] of char;
procedure dfs(x,y,now:longint);
var
j,l:integer;
begin
if now=k then inc(ans)
else
begin
for
i:=x+1 to n do
for j:=1 to n do
if (map[i,j]='#')and(not
vx[i])and(not vy[j])then
begin
vx[i]:=true;
vy[j]:=true;
dfs(i,j,now+1);
vx[i]:=false;
vy[j]:=false;
end;
end;
end;
begin
while true do
begin
readln(n,k);
if (n=-1) and (k=-1) then halt;
for i:=1 to n do
begin
for
j:=1 to n do
read(map[i,j]);
readln;
end;
fillchar(vx,sizeof(vx),false);
fillchar(vy,sizeof(vy),false);
ans:=0;
for i:=1 to n-k+1 do
for j:=1 to n do
if
map[i,j]='#' then
begin
vx[i]:=true;
vy[j]:=true;
dfs(i,j,1);
vx[i]:=false;
vy[j]:=false;
end;
writeln(ans);
end;
end.
n,k,i,j,ans:longint;
vx,vy:array[1..8] of boolean;
map:array[1..8,1..8] of char;
procedure dfs(x,y,now:longint);
var
j,l:integer;
begin
if now=k then inc(ans)
else
begin
for
i:=x+1 to n do
for j:=1 to n do
if (map[i,j]='#')and(not
vx[i])and(not vy[j])then
begin
vx[i]:=true;
vy[j]:=true;
dfs(i,j,now+1);
vx[i]:=false;
vy[j]:=false;
end;
end;
end;
begin
while true do
begin
readln(n,k);
if (n=-1) and (k=-1) then halt;
for i:=1 to n do
begin
for
j:=1 to n do
read(map[i,j]);
readln;
end;
fillchar(vx,sizeof(vx),false);
fillchar(vy,sizeof(vy),false);
ans:=0;
for i:=1 to n-k+1 do
for j:=1 to n do
if
map[i,j]='#' then
begin
vx[i]:=true;
vy[j]:=true;
dfs(i,j,1);
vx[i]:=false;
vy[j]:=false;
end;
writeln(ans);
end;
end.
相关文章推荐
- poj 1321 棋盘问题(DFS,回溯)
- POJ 1321 棋盘问题 简单递归
- POJ 1321 棋盘问题(基础题)
- poj1321棋盘问题
- POJ 1321 棋盘问题
- Poj 1321 棋盘问题
- kuangbin专题一A题 :POJ1321 :棋盘问题
- POJ 1321 棋盘问题 (DFS)
- poj 1321 棋盘问题
- POJ1321——棋盘问题
- poj 1321 棋盘问题
- POJ 1321 棋盘问题
- POJ-1321-棋盘问题
- A_棋盘问题(POJ_1321)
- A - 棋盘问题 POJ - 1321
- POJ 1321 棋盘问题
- POJ 1321, 棋盘问题
- POJ 1321 - 棋盘问题
- poj1321 棋盘问题(状态压缩)
- poj 1321棋盘问题