makerli @ 2023-07-12 21:40:23
6,8,10 WA,其他AC
#include<bits/stdc++.h>
using namespace std;
int n,m;
int fx[5]={0,1,-1,0,0};
int fy[5]={0,0,0,1,-1};
char mg[101][101];
bool f[101][101];
bool b;
inline void dfs(int x,int y)
{
if(x==m&&y==n)
{
b=true;
return;
}
for(int i=1;i<=4;i++)
{
if(x+fx[i]>=1&&x+fx[i]<=m)
if(y+fy[i]>=1&&y+fy[i]<=n)
if(!f[x+fx[i]][y+fy[i]])
{
f[x+fx[i]][y+fy[i]]=true;
dfs(x+fx[i],y+fy[i]);
}
}
}
int 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>>mg[i][j];
if(mg[i][j]=='#')
f[i][j]=1;
}
char t;
cin>>t;
}
dfs(1,1);
if(b)
cout<<"Yes";
else
cout<<"No";
return 0;
}
感谢!!!!!
by __er @ 2023-07-12 22:22:52
@makerli DFS
里所有 n,m
写反了
输入为什么要 char t;cin>>t;
by makerli @ 2023-07-12 22:24:16
谢谢! (那两行多打了,忘了删)
by wangmofan @ 2023-07-16 14:08:28
@_er 谢谢,也解决了我的问题