求助!! 只过了4个点
  • 板块P1605 迷宫
  • 楼主Daniel_yao
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/2/12 18:03
  • 上次更新2023/10/28 08:45:31
查看原帖
求助!! 只过了4个点
519573
Daniel_yao楼主2022/2/12 18:03
#include<bits/stdc++.h>
using namespace std;
const int N = 6;
bool map_[N][N], tmp[N][N];
int n, m, t, x, y, sx, sy, fx, fy, ans;

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {-1, 1, 0, 0};

void dfs(int x1, int y1){
	if(x1 == fx && y1 == fy){
		ans++;
		return ;
	}
	for(int i = 0;i < 3;i++){
		if(tmp[x1+dx[i]][y1+dy[i]] == 0 && map_[x1+dx[i]][y1+dy[i]] == 0 && x1+dx[i] >= 1 && x1+dx[i] <= n && y1+dy[i] >= 1 && y1+dy[i] <= m){
			tmp[x1][y1] = 1;
			dfs(x1+dx[i], y1+dy[i]);
			tmp[x1][y1] = 0;
		}
	}	
}

int main(){
	cin >> n >> m >> t;
	cin >> sx >> sy;
	cin >> fx >> fy;
	for(int i = 1;i <= t;i++){
		cin >> x >> y;
		map_[x][y] = 1;
	}
	tmp[sx][sy] = 1; 
	dfs(sx, sy);
	cout << ans;
	return 0;
}
2022/2/12 18:03
加载中...