跳到正文

题解

迷宫

zhenshizhendezhen约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年2月1日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include <bits/stdc++.h>
using namespace std;
int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int MAP[9][9],vis[9][9],ans;//MAP[i][j]=1表示是障碍物
int n,m,t;
int sx,sy,fx,fy;
void dfs(int x,int y){
	if(x==fx&&y==fy){
		ans++;
		return ;
	}
	vis[x][y]=1;
	for(int i=0;i<4;i++){
		int nx=x+dir[i][0],ny=y+dir[i][1];
		if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&MAP[nx][ny]!=1&&!vis[nx][ny]){
			dfs(nx,ny);
		}
	}
	vis[x][y]=0;
}
int main(){
    cin>>n>>m>>t;
    cin>>sx>>sy>>fx>>fy;
    for(int i=1;i<=t;i++){
    	int x,y;
    	cin>>x>>y;
    	MAP[x][y]=1;
	}
	dfs(sx,sy);
	cout<<ans;
	return 0;
}
原文