not_much_j @ 2024-04-23 17:50:47
using System;
class b3625
{
public static int n,m;
public static int[] dx=new int[]{1,0,0,-1};
public static int[] dy=new int[]{0,1,-1,0};
public static bool ans;
public static bool[,] used=new bool[103,103];
public static void dfs(int x,int y)
{
if(used[x,y]==true)
{
if(x==n&&y==m)
{
ans=true;
return;
}
for(int i=0;i<=3;i++)
{
dfs(x+dx[i],y+dy[i]);
}
}
}
static void Main()
{
string s;
string[] cnt=new string[2];
s=Console.ReadLine();
cnt=s.Split(' ');
n=int.Parse(cnt[0]);
m=int.Parse(cnt[1]);
for(int i=1;i<=n;i++)
{
s=Console.ReadLine();
for(int j=0;j<s.Length;j++)
{
if(s[j]=='.') used[i,j+1]=true;
}
}
dfs(1,1);
if(ans==true)
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
}
}
by wyw666 @ 2024-04-23 18:44:32
dfs没有标记经过的路线,无限递归了