70分求助!!!
  • 板块P1605 迷宫
  • 楼主jntmngm123
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/7/4 19:48
  • 上次更新2024/7/4 21:55:48
查看原帖
70分求助!!!
1120514
jntmngm123楼主2024/7/4 19:48

无论怎么改都不对,#2,#7,#8点都WA了

#include<iostream>
#include<cstring>
using namespace std;
int map[10][10];
int temp[10][10];
int dx[5] = { 0,0,1,-1 }, dy[5] = { 1,-1,0,0 };
int sx, sy, ex, ey;
int tmp_x, tmp_y;
int n, m, t, ans = 0;
void dfs(int x, int y)
{
	if (x == ex && y == ey)
	{
		ans++; return;
	}
	for (int i = 0; i < 4; i++)
	{
		if (!map[x + dx[i]][y + dy[i]] && x + dx[i] >= 1 && y + dy[i] >= 1 && y + dy[i] <= m && x + dx[i] <= n)
		{
			if (!temp[x + dx[i]][y + dy[i]])
			{
				temp[x + dx[i]][y + dy[i]] = 1;
				dfs(x + dx[i], y + dy[i]);
				temp[x + dx[i]][y + dy[i]] = 0;
			}
		}
	}
}
int main()
{
	cin >> n >> m >> t;
	cin >> sx >> sy >> ex >> ey;
	for (int i = 1; i <= t; i++)
	{
		cin >> tmp_x >> tmp_y;
		map[tmp_x][tmp_y] = 1;
	}
	dfs(sx, sy);
	cout << ans;
	return 0;
}
2024/7/4 19:48
加载中...