为什么我连输入都输不进
查看原帖
为什么我连输入都输不进
643377
qweryyzs楼主2024/8/10 10:42

为什么我连输入都输不进

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long long int n,m,a[100][100],bc[110][110];
bool bl=false;
int b[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
void dfs(int x,int y)
{
	int x1,y1;
	if(x==n&&y==m)
	{
		bl=true;
		return;
	}
	for(int i=0;i<4;i++)
	{
		x1=x+b[i][1];
		y1=y+b[i][2];
		if(x1==n+1||x1==0||y1==m+1||y1==0)
			continue;
		if(a[x1][y1]==0&&bc[x1][y1])
		{
			bc[x1][y1]=1;
			dfs(x1,y1);
			bc[x1][y1]=0;
		}
		
	}
}
int main()
{
	char c;
	cin>>n,m;
	for(int i=1;i<=n;i++)
	{
		for(int l=1;l<=m;l++)
		{
			cin>>c;
			if(c=='#')
				a[i][l]=2;
			else
				a[i][l]=0;
		}
	}
	bc[1][1]=1;
	dfs(1,1);
	if(bl==true)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

2024/8/10 10:42
加载中...