代码:
#include<bits/stdc++.h>
using namespace std;
int n,m,t;
bool a[105][105];
int ans=0;
int hx,hy;
struct s{
int x,y;
}f[10005];
void ou(int x){
for(int i=1;i<x;i++){
cout<<"("<<f[i].x<<","<<f[i].y<<")->";
}
cout<<"("<<f[x].x<<","<<f[x].y<<")";
cout<<endl;
}
void dfs(int x,int y,int b){
f[b].x=x;
f[b].y=y;
if(x==hx && y==hy){
ans++;
ou(b);
return;
}
a[x][y]=1;
if(a[x+1][y]==0 && !a[x+1][y]&&x+1<=n){
dfs(x+1,y,b+1),a[x+1][y]=0;
}
if(a[x][y+1]==0 && !a[x][y+1]&&y+1<=m){
dfs(x,y+1,b+1),a[x][y+1]=0;
}
if(a[x-1][y]==0 && !a[x-1][y]&&x-1>0){
dfs(x-1,y,b+1),a[x-1][y]=0;
}
if(a[x][y-1]==0 && !a[x][y-1]&&y-1>0){
dfs(x,y-1,b+1),a[x][y-1]=0;
}
}
int main(){
cin>>n>>m;
int x,y;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
a[i][j]=!a[i][j];
}
}
cin>>x>>y>>hx>>hy;
dfs(x,y,1);
if(ans==0)cout<<-1;
return 0;
}