20分求助!!!
  • 板块P1605 迷宫
  • 楼主J_Kobe
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/1/13 08:36
  • 上次更新2024/1/13 08:47:11
查看原帖
20分求助!!!
844496
J_Kobe楼主2024/1/13 08:36
#include <bits/stdc++.h>
using namespace std;

int n, m, t, ans = 0, x, y, x2, y2;
char s[10][10];
bool f[10][10];

void dfs(int x, int y)
{
	if (x < 1 || x > n || y < 0 || y > m)
	{
		return ;
	}
	if (x == x2 + 1 && y == y2 + 1)
	{
		ans++;
		return ;
	}
	if (f[x+1][y] == 0 && s[x+1][y] == '.')
	{
		f[x+1][y] = 1;
		dfs(x + 1, y);
	}
	if (f[x-1][y] == 0 && s[x-1][y] == '.')
	{
		f[x-1][y] = 1;
		dfs(x - 1, y);
	}
	if (f[x][y+1] == 0 && s[x][y+1] == '.')
	{
		f[x][y+1] = 1;
		dfs(x, y + 1);
	}
	if (f[x][y-1] == 0 && s[x][y-1] == '.')
	{
		f[x][y-1] = 1;
		dfs(x, y - 1);
	}
}

signed main()
{
	scanf("%d%d%d", &n, &m, &t);
	scanf("%d%d%d%d", &x, &y, &x2, &y2);
	while (t--)
	{
		int fx, fy;
		scanf("%d%d", &fx, &fy);
		s[fx+1][fy+1] = '#';
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			if (s[i][j] != '#')
			{
				s[i][j] = '.';
			}
		}
	}
	f[x+1][y+1] = 1;
	dfs(x + 1, y + 1);
	cout << ans;
	return 0;
}
2024/1/13 08:36
加载中...