棋盘上 A 点有一个过河卒,需要走到目标 B点。卒行走的规则:可以向下、或者向右。同时在棋盘上 C点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点。因此称之为“马拦过河卒”。

棋盘用坐标表示,A 点 (0, 0)、B 点 (n, m),同样马的位置坐标是需要给出的。

过河卒

现在要求你计算出卒从 A 点能够到达 B点的路径的条数,假设马的位置是固定不动的,并不是卒走一步马走一步。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
long long a[25][25];
bool b[25][25];
int main(){
	int x,y,x1,y1;
	cin>>x>>y>>x1>>y1;
	a[2][2]=1;
	b[x1-2+2][y1+1+2]=1;
	b[x1-2+2][y1-1+2]=1;
	b[x1-1+2][y1+2+2]=1;
	b[x1-1+2][y1-2+2]=1;
	b[x1+1+2][y1+2+2]=1;
	b[x1+1+2][y1-2+2]=1;
	b[x1+2+2][y1+1+2]=1;
	b[x1+2+2][y1-1+2]=1;
	b[x1+2][y1+2]=1;
	for(int i=0;i<=x;i++){
		for(int j=0;j<=y;j++){
			if(i==0&&j==0) continue;
			if(!b[i+2][j+2])
				a[i+2][j+2]=a[i+1][j+2]+a[i+2][j+1];
		}
	}
	cout<<a[x+2][y+2];
	return 0;
} 

相关文章:

  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2021-04-24
  • 2021-10-20
  • 2021-06-05
  • 2021-12-22
  • 2021-11-19
猜你喜欢
  • 2022-01-04
  • 2022-01-06
  • 2021-06-20
相关资源
相似解决方案