O(2^n)我要严重吐槽这个题目,那个n还是我补上的。使用多个数组记录列和对角线的情况,若皇后可在对角线上连成直线,则横纵坐标之和、之差均相等。var d:array[1..20] of longint; a,b,c:array[-100..160] of 0..1; t,n,z:longint;PRocedure try(s:longint);var i:longint;begin if s>n then begin if z<>3 then begin inc(z); for i:=1 to n do write(d[i],' '); writeln; end; inc(t); exit; end; for i:=1 to n do if (a[i]=0)and(b[s-i]=0)and(c[s+i]=0) then begin d[s]:=i; a[i]:=1; b[s-i]:=1; c[s+i]:=1; try(s+1); a[i]:=0; b[s-i]:=0; c[s+i]:=0; end;end;begin readln(n); try(1); writeln(t);end.