过河卒的题解
2026-09-13 16:08:42
发布于:湖南
2阅读
0回复
0点赞

首先,我们先知道这道题的方法:递推。
其次,我们再找到马的8个方向
最后,写!
#include<bits/stdc++.h>
using namespace std;
long long n,m,x,y;
long long dx[9] = {-2,-1,1,2,2,1,-1,-2},dy[9] = {1,2,2,1,-1,-2,-2,-1};
long long a[100][100],b[100][100];
int main()
{
cin >>n>>m>>x>>y;
a[0][0] = 1;
b[x][y] = 1;
for(long long i = 0;i<8;i++)
{
long long tx = x+dx[i],ty = y+dy[i];
if(tx<0||tx>n||ty<0||ty>m) continue;
b[tx][ty] = 1;
}
for(long long i = 0;i<=n;i++)
{
for(long long j= 0;j<=m;j++)
{
if(!b[i][j])
{
if(i-1>=0) a[i][j]+=a[i-1][j];
if(j-1>=0) a[i][j]+=a[i][j-1];
}
}
}
cout <<a[n][m]<<"\n";
return 0;
}
这里空空如也





有帮助,赞一个