题目链接
本蒟蒻写了一深搜,但 #2,#5,#6 WA了。。
我的代码:
#include<bits/stdc++.h>
using namespace std;
char c;
bool b[110][110],vis[110][110];
int n,m,dx[]={0,0,1,0,-1},dy[]={0,1,0,-1,0},cnt;
void dfs(int x,int y)
{
cnt++;
// printf("x = %d,y = %d,cnt = %d\n",x,y,cnt);
if(x == n && y == m)
{
puts("Yes");
exit(0);
}
if(cnt > n * m)
{
puts("No");
exit(0);
}
for(int i = 1;i <= 4;i++)
{
int yx = x + dx[i],yy = y + dy[i];
if(1 <= yx && yx <= n && 1 <= yy && yy <= m)
{
if(vis[yx][yy] == false && b[yx][yy] == false)
{
vis[yx][yy] = true;
dfs(yx,yy);
vis[yx][yy] = false;
}
}
}
}
signed main()
{
cin >> n >> m;
for(int i = 1;i <= n;i++)
{
for(int j = i;j <= m;j++)
{
cin >> c;
if(c == '#')
b[i][j] = true;
}
}
dfs(1,1);
return 0;
}
请求 dalaos 帮助!!!