p1121m.pas
来自「www.vijos.cn上一些习题的参考源码」· PAS 代码 · 共 97 行
PAS
97 行
program p1121m;
const
MAXN=15;
MAXM=15;
ma:array[1..8,1..2] of integer=((-2,1),(-1,2),(1,2),(2,1),(-2,-1),(-1,-2),(1,-2),(2,-1));
var
can:array[0..MAXN,0..MAXM] of boolean;
num:array[0..MAXN,0..MAXM] of longint;
n,m,mx,my:integer;
i,j,d,x,y,k:integer;
{fout:text;}
function bound(x,y:integer):boolean;
begin
if (x>=0) and (x<=n) and (y>=0) and (y<=m) then bound:=true
else bound:=false;
end;
procedure init;
begin
fillchar(num,sizeof(num),0);
fillchar(can,sizeof(can),true);
can[mx,my]:=false; {注意:不要忘了马所在的点}
for i:=1 to 8 do
if bound(mx+ma[i,1],my+ma[i,2]) then
can[mx+ma[i,1],my+ma[i,2]]:=false;
end;
procedure move(k:integer; var x,y:integer);
begin
case k of
1:inc(x);
2:inc(y);
end;
end;
begin
readln(n,m,mx,my);
init;
num[0,0]:=1;
{num[0,1]:=1;
num[1,0]:=1;}
for i:=0 to n do begin
for j:=0 to m do begin
if not can[i,j] then continue;
for k:=1 to 2 do begin
x:=i; y:=j;
move(k,x,y);
if can[x,y] and bound(x,y) then
inc(num[x,y],num[i,j]);
end;
end;
end;
{for d:=0 to n do begin
for i:=0 to d do begin
j:=d-i;
if not can[i,j] then continue;
for k:=1 to 2 do begin
x:=i; y:=j;
move(k,x,y);
if can[x,y] and bound(x,y) then
inc(num[x,y],num[i,j]);
end;
end;
end;
for d:=n+1 to 2*n do begin
for i:=1 to n do begin
j:=d-i;
if not can[i,j] then continue;
for k:=1 to 2 do begin
x:=i; y:=j;
move(k,x,y);
if can[x,y] and bound(x,y) then
inc(num[x,y],num[i,j]);
end;
end;
end;}
writeln(num[n,m]);
{assign(fout,'t1.out'); rewrite(fout);
for i:=0 to n do begin
for j:=0 to n do begin
write(fout,num[i,j]:3);
end;
writeln(fout);
end;
close(fout);}
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?