记录编号 |
61759 |
评测结果 |
AAAAAAAAAA |
题目名称 |
填数 |
最终得分 |
100 |
用户昵称 |
CAX_CPG |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
1.134 s |
提交时间 |
2013-06-16 11:24:03 |
内存使用 |
31.14 MiB |
显示代码纯文本
var a:array[0..20,0..20]of longint;
b:array[0..200,0..200,0..200]of longint;
v,vv:array[0..400]of boolean;
i,j,k,n:longint;
procedure dfs(x,y:longint);
var i,j,k,kk:longint;
begin
if(x=n)and(y=n)then
begin
for i:=1 to n do
begin for j:=1 to n do write(a[i,j],' ');writeln;end;
close(output);halt;
end;
x:=x+y div n;y:=y mod n;
k:=a[x,y];kk:=a[x-1,y+1];
for i:=1 to b[k,kk,0]do
if not vv[b[k,kk,i]]then
begin
a[x,y+1]:=b[k,kk,i];
vv[b[k,kk,i]]:=true;
dfs(x,y+1);
vv[b[k,kk,i]]:=false;
end;
end;
begin
assign(input,'tianshu.in');reset(input);
assign(output,'tianshu.out');rewrite(output);
readln(n);close(input);
if n=1 then begin writeln('NO');close(output);halt;end;
fillchar(v,sizeof(v),true);
v[1]:=false;
for i:=2 to 2*n*n do
if v[i]then for j:=i to 2*n*n div i do v[i*j]:=false;
for i:=0 to n*n do
for j:=0 to n*n do
for k:=1 to n*n do
if (v[i+k]or(i=0))and(v[j+k]or(j=0))and(i<>j)and(j<>k)and(i<>k)then begin
inc(b[i,j,0]);b[i,j,b[i,j,0]]:=k;
end;
a[1,1]:=1;vv[1]:=true;
dfs(1,1);
writeln('NO');close(output);
end.