转自:https://www.cnblogs.com/OctoptusLian/p/7429645.html
void dfs(int x,int y,int step)
{
int tx,ty;
int next[4][2]= {{-1,0},{1,0},{0,-1},{0,1}};
if(x==endx &&y==endy)
{
if(step<mi)
mi=step;
return;
}
for(int i=0; i<=3; i++)
{
tx=x+next[i][0];
ty=y+next[i][1];
if(tx<1||tx>n||ty<1||ty>m)
continue;
if(a[tx][ty] == 0 &&book[tx][ty]==0)
{
book[tx][ty]=1;
dfs(tx,ty,step+1);
book[tx][ty] = 0;
}
}
return;
}