B3625 迷宫寻路 深搜70分求调
  • 板块题目总版
  • 楼主ice_fish01
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/3/30 23:32
  • 上次更新2023/10/23 19:59:20
查看原帖
B3625 迷宫寻路 深搜70分求调
770910
ice_fish01楼主2023/3/30 23:32

题目链接
本蒟蒻写了一深搜,但 #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 帮助!!!

2023/3/30 23:32
加载中...