先展示一下我用bfs写的,不过错了,一个wa,一个ac,2个mle
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define PII pair<int,int>
#define x first
#define y second
#define int long long
const int N = 1e3;
bool ma[21][21]={};
int f[40][40]={};
void bfs();
void solve();
//马可以走的方式 sum = 9
int dx1[]={0, -1, -2, -2, -1, +1, +2, +2, +1};
int dy1[]={0, -2, -1, +1, +2, +2, +1, -1, -2};
//小兵可以走的位置
int dx[] = {1,0};//右和下
int dy[] = {0,1};
int n,m,xm,ym, ans = 0;
signed main()
{
IOS;
cin >> n >> m >> xm >> ym;
//n++,m++,xm++,ym++;//全体向右下移动一个位置
solve();//给马以及他可以影响的点打标记
bfs();
}
void bfs()
{
int a, b;
queue<PII> q;
q.push( {0,0} );
PII t;
while( ! q.empty( ) )
{
t = q.front();
q.pop();
if(ma[t.x][t.y] == true ) continue;
if(t.x == n && t.y == m) ans ++;
for( int i = 0 ; i < 2 ; i ++ )
{
a = t.x + dx[i] , b = t.y + dy[i];
if( a > n || b > m ) continue;
q.push({a, b});
}
}
cout << ans;
}
void solve()
{
int a,b;
for( int i = 0 ; i < 9 ; i ++ )
{
a = xm + dx1[i] , b = xm + dy1[i];
if( a>=0 && b >=0 )
{
ma[a][b] = true;
}
}
}