## 代码

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
#define N 50
#define LL long long

LL sol[N][N];
bool vis[N][N];
struct hp{int x,y;};
int dx[8]={-2,-2,-1,-1,1,1,2,2};
int dy[8]={-1,1,-2,2,-2,2,-1,1};
queue <hp> q;

void spfa()
{
memset(step,127,sizeof(step));step[sx][sy]=0;
memset(sol,0,sizeof(sol));sol[sx][sy]=1;
memset(vis,0,sizeof(vis));vis[sx][sy]=true;
while (!q.empty()) q.pop();q.push((hp){sx,sy});
while (!q.empty())
{
hp now=q.front();q.pop();
vis[now.x][now.y]=false;
for (int i=0;i<8;++i)
{
int x=now.x+dx[i],y=now.y+dy[i];
if (!(x>=1&&x<=n&&y>=1&&y<=m)||a[x][y]==2) continue;
int len;
if (a[x][y]==0) len=1; else len=0;
{
step[x][y]=step[now.x][now.y]+1;
sol[x][y]=sol[now.x][now.y];
if (!vis[x][y])
{
vis[x][y]=true;
q.push((hp){x,y});
}
}
{
if (step[now.x][now.y]+1<step[x][y])
{
step[x][y]=step[now.x][now.y]+1;
sol[x][y]=sol[now.x][now.y];
if (!vis[x][y])
{
vis[x][y]=true;
q.push((hp){x,y});
}
}
else if (step[now.x][now.y]+1==step[x][y])
{
sol[x][y]+=sol[now.x][now.y];
if (!vis[x][y])
{
vis[x][y]=true;
q.push((hp){x,y});
}
}
}
}
}
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
{
scanf("%d",&a[i][j]);
if (a[i][j]==3) sx=i,sy=j;
if (a[i][j]==4) tx=i,ty=j;
}
spfa();
{
puts("-1");
return 0;
}
}

08-18 1550
10-28 1143
09-19 507