社区讨论

50分,大佬救救我!

P1605迷宫参与者 4已保存回复 11

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
11 条
当前快照
1 份
快照标识符
@lo8h5zqb
此快照首次捕获于
2023/10/27 18:33
2 年前
此快照最后确认于
2023/10/27 18:33
2 年前
查看原帖
CPP
#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;
}

回复

11 条回复,欢迎继续交流。

正在加载回复...