讨论 / 大家帮帮忙看看为什么这个程序0分
HOH 2012-07-13 18:19:00
点我顶贴 收藏 删除
program nqueens;

var s:array[1..13]of integer;

a:array[1..13]of boolean;

b:array[1..27]of boolean;

c:array[-13..13]of boolean;

n:integer;

sum:longint;

procedure place(i:integer);

var j:integer;

procedure print;

var x:integer;

begin

for x:=1 to n do

begin

write(s[x],' ');

end;

writeln;

end;

begin

if(i>n)then

begin

if(sum<3)then print;

inc(sum);

exit;

end;

if(i<=n)then

begin

for j:=1 to n do

begin

if((a[j]=true)and(b[j+i]=true)and(c[j-i]=true))then

begin

s[i]:=j;

a[j]:=false;

b[j+i]:=false;

c[j-i]:=false;

place(i+1);

a[j]:=true;

b[j+i]:=true;

c[j-i]:=true;

end;

end;

end;

end;

begin

read(n);

fillchar(a,sizeof(a),true);

fillchar(b,sizeof(b),true);

fillchar(c,sizeof(c),true);

sum:=0;

place(1);

write(sum);

end.

查看更多回复
提交回复