填数
program fillnum; const maxn=1000; var b:array[1..maxn]of boolean; s,n:integer; map:array[1..100,1..100]of integer; procedure play(x,y:integer); var i,j:integer; begin //find one if x=n+1 then begin inc(s); for i:=1 to n do begin for j:=1 to n do write(map[i,j]); writeln; end; writeln; exit; end; //huan hang if y=n+1 then play(x+1,1) else begin j:=0; //the min num if (y>1) then if map[x,y-1]>j then j:=map[x,y-1]; if (x>1) then if map[x-1,y]>j then j:=map[x-1,y]; //di gui kuang du qi youxia fang neng zhan for i:=j+1 to n*n-(n-y+1)*(n-x+1)+1 do if b[i] then begin b[i]:=false; map[x,y]:=i; play(x,y+1); b[i]:=true; end; end; end; begin assign(input,'win.in'); assign(output,'win.out'); reset(input); rewrite(output); //initialization fillchar(b,sizeof(b),1); s:=0; readln(n); play(1,1); writeln(s); close(input); close(output); end.
n2的棋盘,填1~n2个数,要求下比上大,左比右大。