Shrimp123 @ 2024-10-25 00:10:22
#include<bits/stdc++.h>
using namespace std;
struct xy {
int x,y;
};
string bfs(vector<string>s,int n,int m)
{
map<vector<string>,xy>d;
queue<vector<string>>q;
s[0][0]='0';
d[s].x=0;
d[s].y=0;
q.push(s);
s[0][0]='.';
int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};
while(!q.empty()) {
vector<string>now=q.front();
q.pop();
int x=d[now].x;
int y=d[now].y;
if(x==m-1&&y==n-1)return "Yes";
for(int i=0; i<4; i++) {
int xx=x+fx[i];
int yy=y+fy[i];
if(xx>=0&&xx<m&&yy>=0&&yy<n&&(now[yy][xx]!='#')) {
//cout<<"yy:"<<yy<<" xx:"<<xx<<endl;
now[yy][xx]='0';
if(!d.count(now)) {
q.push(now);
d[now].x=xx;
d[now].y=yy;
}
now[yy][xx]='.';
}
}
}
return "No";
}
int main ()
{
int n,m;
string x;
cin>>n>>m;
vector<string>a(n);
for(int i=0; i<n; i++) {
cin>>x;
a[i]=x;
}
// for(auto i:a)cout<<i<<endl;
// cout<<a[1][1]<<endl;
cout<<bfs(a,n,m)<<endl;
return 0;
}
by QwQlaoda @ 2024-10-25 00:15:55
vis标记有吗
by gaoju @ 2024-10-25 20:58:58
改BFS,记忆化都过不了
by gaoju @ 2024-10-25 20:59:14
@QwQlaoda 他有的