- 马拦过河卒
- 2014-08-26 21:33:36 @
如果马的位置是(1,0),那么赋初值时f[2,0],f[3,0],...,f[n,0]都是为1,而是0,同样f[0,3],f[0,4],...,f[0,m]也为0.所以赋初值时要进行判断.
2 条评论
-
wwwwww931121 LV 4 @ 2017-02-09 09:59:39
谢谢
-
2014-10-17 19:45:32@
第三个点需要特判;代码:
var n,m,x,y,i,j:longint;
a,f:array[-1000..1000,-1000..1000] of longint;
begin
read(n,m);
readln(x,y);
a[x,y]:=-1;
a[x+2,y+1]:=-1;
a[x+2,y-1]:=-1;
a[x-2,y+1]:=-1;
a[x-2,y-1]:=-1;
a[x+1,y+2]:=-1;
a[x+1,y-2]:=-1;
a[x-1,y+2]:=-1;
a[x-1,y-2]:=-1;
for i:=0 to n do begin if a[i,0]=-1 then break;f[i,0]:=1;end;
for i:=0 to m do begin if a[0,i]=-1 then break;f[0,i]:=1;end;
for i:=1 to n do
for j:=1 to m do
if a[i,j]<>-1 then f[i,j]:=f[i-1,j]+f[i,j-1];
writeln(f[n,m]);
end.
- 1