50分,大佬救救我!
  • 板块P1605 迷宫
  • 楼主guoyibo
  • 当前回复11
  • 已保存回复11
  • 发布时间2022/7/25 09:59
  • 上次更新2023/10/27 18:33:04
查看原帖
50分,大佬救救我!
757355
guoyibo楼主2022/7/25 09:59
#include<bits/stdc++.h>

using namespace std;

int map1[1005][1005] = {0};//0:可走 1:不可走 
int visit[1005][1005] = {0};
int n,m,t,cnt = 0;
int sx,sy,tx,ty;
int xx=0,yy=0;

void dfs(int x,int y){
	if(x==tx and y==ty){
		cnt++;
		return ;
	}
	else{
		xx=x-1,yy=y;
		if(map1[xx][yy]==0 and visit[xx][yy]==0 and xx>=1 and yy>=1 and xx<=n and yy<=m){
			visit[xx][yy] = 1;
			dfs(xx,yy);
			visit[xx][yy] = 0;
		}
		xx=x;yy=y+1;
		if(map1[xx][yy]==0 and visit[xx][yy]==0 and xx>=1 and yy>=1 and xx<=n and yy<=m){
			visit[xx][yy] = 1;
			dfs(xx,yy);
			visit[xx][yy] = 0;
		}
		xx=x+1;yy=y;
		if(map1[xx][yy]==0 and visit[xx][yy]==0 and xx>=1 and yy>=1 and xx<=n and yy<=m){
			visit[xx][yy] = 1;
			dfs(xx,yy);
			visit[xx][yy] = 0;
		}
		xx=x;yy=y-1;
		if(map1[xx][yy]==0 and visit[xx][yy]==0 and xx>=1 and yy>=1 and xx<=n and yy<=m){
			visit[xx][yy] = 1;
			dfs(xx,yy);
			visit[xx][yy] = 0;
		}
	}
	
}
int main(){
	cin>>n>>m>>t;
	cin>>sx>>sy>>tx>>ty;
	for(int i=1;i<=t;i++){
		int x,y;
		cin>>x>>y;
		map1[x][y] = 1;
	}
	visit[sx][sy] = 1;
	dfs(sx,sy);
	cout<<cnt;
	return 0;
}
2022/7/25 09:59
加载中...