很离谱的结果,输出的东西长度都是对的,但是每次输出的具体坐标全错。。
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#define int long long
using namespace std;
int n,m,fx,fy,ex,ey;
int a[20][20];
int lu[9007][2];
inline void out(int k){
for(int i=1;i<=k;i++){
printf("(%lld, %lld)",a[i][0],a[i][1]);
if(i!=k) printf("->");
}
}
void dfs(int x,int y,int k){
if(x>=1&&x<=n&&y>=1&&y<=m&&a[x][y]==1){
lu[k][0]=x;
lu[k][1]=y;
a[x][y]=0;
dfs(x,y-1,k+1);
dfs(x-1,y,k+1);
dfs(x,y+1,k+1);
dfs(x+1,y,k+1);
a[x][y]=1;
}
if(x==ex&&y==ey){
out(k);
cout<<endl;
return ;
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
cin>>fx>>fy>>ex>>ey;
dfs(fx,fy,0);
return 0;
}