40分求助
#include<bits/stdc++.h>
//cout<<fixed<<setprecision(2);
using namespace std;
int d[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
char mp[115][17];
int vis[115][17];
bool f = false;
int n,m;
struct p{
int x,y;
}path[10000000];
bool check(int x,int y){
return x>=1 && x<=n && y>=1 && y<=m && mp[x][y] == '.' && !vis[x][y];
}
int k = 0,cnt = 0;
void dfs(int x,int y){
if(x==n && y==m){
for(int i = 0;i<k;i++){
cout<<path[i].x<<" "<<path[i].y<<endl;
}
return;
}
for(int i = 0;i<4;i++){
int nx = x+d[i][0];
int ny = y+d[i][1];
if(check(nx,ny)){
path[k++] = {nx,ny};
vis[nx][ny] = 1;
dfs(nx,ny);
k--;
}
}
}
int main(){
cin>>n>>m;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
cin>>mp[i][j];
}
}
dfs(0,1);
return 0;
}