1314:【例3.6】过河卒(Noip2002)
时间限制: 1000 ms 内存限制: 65536 KB
提交数: 13186 通过数: 5567
【题目描述】
棋盘上A点有一个过河卒,需要走到目标B点。卒行走的规则:可以向下、或者向右。同时在棋盘上的某一点有一个对方的马(如C点),该马所在的点和所有跳跃一步可达的点称为对方马的控制点,如图3-1中的C点和P1,……,P8,卒不能通过对方马的控制点。棋盘用坐标表示,A点(0,0)、B点(n, m) (n,m为不超过20的整数),同样马的位置坐标是需要给出的,C≠A且C≠B。现在要求你计算出卒从A点能够到达B点的路径的条数。
#include <iostream> using namespace std; long long map23; long long n,m;long long a,b; long long bfs(int x,int y) { if(mapx!=0) return mapx; if(x>n || y>m) return 0; if(x+2==a && y+1==b) return 0; if(x+1==a && y+2==b) return 0; if(x-2==a && y+1==b) return 0; if(x-1==a && y+2==b) return 0; if(x+2==a && y-1==b) return 0; if(x+1==a && y-2==b) return 0; if(x-2==a && y-1==b) return 0; if(x-1==a && y-2==b) return 0; if(x==a && y==b) return 0; long long k=bfs(x+1,y); long long j=bfs(x,y+1); mapx=k+j; return mapx; } int main() { cin>>n>>m; cin>>a>>b; mapn=1; cout<<bfs(0,0); }
Comment here is closed