棋盘上A点有一个过河卒,需要走到目标B点。卒行走的规则:可以向下、或者向右。同时在棋盘上的某一点有一个对方的马(如C点),该马所在的点和所有跳跃一步可达的点称为对方马的控制点,如图3-1中的C点和P1,……,P8,卒不能通过对方马的控制点。棋盘用坐标表示,A点(0,0)、B点(n, m) (n,m为不超过20的整数),同样马的位置坐标是需要给出的,C≠A且C≠B。现在要求你计算出卒从A点能够到达B点的路径的条数。
输入
给出n、m和C点的坐标。
输出
从A点能够到达B点的路径的条数。
输入样例
8 6 0 4
输出样例
1617
代码:
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int dx[]={-2,-2,-1,-1,1,1,2,2};
int dy[]={-1,1,-2,2,-2,2,-1,1};
long long a[25][25] ;
int f[25][25];
int main()
{
int n , m , x , y;
cin>>n>>m>>x>>y;
x = x + 1;
y = y + 1;
f[x][y] = 1;
for(int i = 0 ; i < 8 ; i++)
{
int x1 = x + dx[i];
int y1 = y + dy[i];
if(x1 > 0 && y1 > 0 )
f[x1][y1] = 1;
}
a[1][0] = 1;
for(int i = 1 ; i <= n + 1 ; i++)
{
for(int j = 1 ; j <= m + 1; j++)
{
if(f[i][j] == 0)
a[i][j] = a[i-1][j] + a[i][j-1];
}
}
cout<<a[n+1][m+1];
return 0;
}