50WA求调!!!
  • 板块P1605 迷宫
  • 楼主George_qwe
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/1/13 16:03
  • 上次更新2024/1/13 19:08:05
查看原帖
50WA求调!!!
1068756
George_qwe楼主2024/1/13 16:03

代码:

using namespace std;
bool map_[10][10];//地图 
bool temp[10][10];//是否访问 
int b1[4]= {0,0,1,-1},b2[4]= {1,-1,0,0};
int sx,sy,fx,fy, n,m,x,y,t,nx,ny,ans=0;
void search(int x,int y){
	if(x==fx&&y==fy){
		ans++;
		return;
	}
	else{
		for(int i=0;i<4;i++){
			nx=x+b1[i],ny=y+b2[i];
			if(temp[nx][ny]==0 && map_[nx][ny]==0 &&nx>0&&nx<=n &&ny>0&&ny<=m){
				temp[nx][ny]=1;
				search(nx,ny);
				temp[nx][ny]=0;
			}
		} 
	}
	return;
}
int main(){
	cin>>n>>m>>t>>sx>>sy>>fx>>fy;
	for(int i=1; i<=t; i++){
		cin>>x>>y;
		map_[x][y]=1;
	}
	map_[sx][sy]=1;
	search(sx,sy);
	cout<<ans;
	return 0;
}```
2024/1/13 16:03
加载中...