wikioi1010 过河卒

来源:互联网 发布:ae cc mac 编辑:程序博客网 时间:2024/06/06 02:44
1010 过河卒  2002年NOIP全国联赛普及组
 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 黄金 Gold
 题解
题目描述 Description
 如图,A 点有一个过河卒,需要走到目标 B 点。卒行走规则:可以向下、或者向右。同时在棋盘上的任一点有一个对方的马(如上图的C点),该马所在的点和所有跳跃一步可达的点称为对方马的控制点。例如上图 C 点上的马可以控制 9 个点(图中的P1,P2 … P8 和 C)。卒不能通过对方马的控制点。




  棋盘用坐标表示,A 点(0,0)、B 点(n,m)(n,m 为不超过 20 的整数,并由键盘输入),同样马的位置坐标是需要给出的(约定: C不等于A,同时C不等于B)。现在要求你计算出卒从 A 点能够到达 B 点的路径的条数。


1<=n,m<=15




输入描述 Input Description
 键盘输入
   B点的坐标(n,m)以及对方马的坐标(X,Y){不用判错}


输出描述 Output Description
  屏幕输出
    一个整数(路径的条数)。


样例输入 Sample Input
 6 6 3 2


样例输出 Sample Output

17


题解:f[i,j]=f[i-1,j]+f[i,j-1],控制点的不加

const  maxn=15;  dx:array[1..8]of integer=(1,2,-1,-2,1,2,-1,-2);  dy:array[1..8]of integer=(2,1,2,1,-2,-1,-2,-1);var  f:array[-1..maxn,-1..maxn]of longint;  n,m,x,y,i,j:longint;procedure init;var  i:longint;begin  readln(n,m,x,y);  for i:=1 to 8 do    if (x+dx[i]>=0)and(x+dx[i]<=n)and(y+dy[i]>=0)and(y+dy[i]<=n) then f[x+dx[i],y+dy[i]]:=-1;  f[x,y]:=-1;end;begin  init;  f[0,0]:=1;  for i:=0 to n do    for j:=0 to m do    begin      if f[i,j]=-1 then continue;      if f[i-1,j]<>-1 then f[i,j]:=f[i,j]+f[i-1,j];      if f[i,j-1]<>-1 then f[i,j]:=f[i,j]+f[i,j-1];    end;  writeln(f[n,m]);end.


0 0