问题遇到的现象和发生背景
运行结果及报错内
输入
3
001
101
100
1 1 3 3
输出4
我的解答思路和尝试过的方法
我想要达到的结果
运行正常,输出答案
```c++和c
#include<stdio.h>
int n,x1,y1,x2,y2,count=10000000;
char arr[1002][1002];
const int direction1[5]={1,-1,0,0,0},direction2[5]= {0,0,1,-1,0};
void DFS(int a,int b,int temp);
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%s",arr[i]+1);
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
DFS(x1,y1,0);
printf("%d",count);
return 0;
}
void DFS(int a,int b,int temp)
{
if(arr[a][b]=='1'||a<1||b<1||a>n||b>n) return;
if(a==x2&&b==y2)
{
if(temp<count)
count=temp;
return;
}
for(int i=0;i<4;i++)
DFS(a+direction1[i],b+direction2[i],temp+1);
}
```