90分,测试点6WA,求指正!!!
  • 板块P1605 迷宫
  • 楼主qyzzyqlqj
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/7/23 16:01
  • 上次更新2024/7/23 16:38:10
查看原帖
90分,测试点6WA,求指正!!!
1269755
qyzzyqlqj楼主2024/7/23 16:01
#include<bits/stdc++.h>
using namespace std;
int n, m, t, sx, sy, fx, fy;
int ans[10][10] = { 0 }, vis[10][10] = { 0 };
int cnt, dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
void dfs(int x,int y) {
	if (x == fx && y == fy) {
		cnt++;
		return;
	}
	if (x<1 || x>m || y<1 || y>n || vis[x][y] || !ans[x][y])return;
	vis[x][y] = 1;
	for (int i = 0; i < 4; i++) {
		dfs(x + dx[i], y + dy[i]);
	}
	vis[x][y] = 0;
	return;
}

int main() {
	cin >> n >> m >> t >> sx >> sy >> fx >> fy;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			ans[i][j] = 1;
		}
	}
	for (int i = 0; i < t; i++) {
		int tx = 0, ty = 0;
		cin >> tx >> ty;
		ans[tx][ty] = 0;
	}
	dfs(sx, sy);
	cout << cnt << endl;

	return 0;
}
2024/7/23 16:01
加载中...