问题出现在这几处
首先需要在第一个begin后打上fillchar(a,sizeof(a),true);不然a数组初始都是FALSE
for i:=0 to n do
for j:=0 to n do
if a[i,j]=false then f[i,j]:=0 else begin
if (i>0) and (j>0) then f[i,j]:=1 //这里至少该是i=0 or j=0 时在边上的时候赋值为1,而且你还要判断这个点上/左方是否被马踩到,踩到就应该为0
else f[i,j]:=f[i-1,j]+f[i,j-1];end; //这里还要判断(i-1,j) (i,j-1)是不是马能踩到的
writeln(f[x,y]);
修改后:
for i:=0 to n do
for j:=0 to n do
if a[i,j]=false then f[i,j]:=0 else begin
if a[i-1,j] then inc(f[i,j],f[i-1,j]);
if a[i,j-1] then inc(f[i,j],f[i,j-1]);
end;
writeln(f[x,y]);
完整
var n,m,x,y,i,j:longint;
a:array[-25..25,-25..25] of boolean;
f:array[-25..25,-25..25] of longint;
begin
readln(n,m,x,y);
fillchar(a,sizeof(a),true);
a[x+2,y+1]:=false;
a[x+1,y+2]:=false;
a[x-1,y+1]:=false;
a[x-2,y+1]:=false;
a[x-2,y-1]:=false;
a[x-1,y-1]:=false;
a[x+1,y-2]:=false;
a[x+2,y-1]:=false;
for i:=0 to n do
for j:=0 to n do
if a[i,j]=false then f[i,j]:=0 else begin
if a[i-1,j] then inc(f[i,j],f[i-1,j]);
if a[i,j-1] then inc(f[i,j],f[i,j-1]);
end;
writeln(f[x,y]);
end.
不懂的追问