60分求助~~
  • 板块P1605 迷宫
  • 楼主Weizhuo_Zhao
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/7/28 12:27
  • 上次更新2023/11/3 07:15:12
查看原帖
60分求助~~
681558
Weizhuo_Zhao楼主2023/7/28 12:27
#include<bits/stdc++.h>
using namespace std;
int ans=0,n,m,t,sx,sy,fx,fy,ifx[4]={0,0,-1,1},ify[4]={-1,1,0,0};
bool b[15][15],txy[15][15];
void dfs(int x,int y){
	if(x==fx&&y==fy)
		ans++;
	else{
		for(int i=0;i<=3;i++){
			int xx=x+ifx[i],yy=y+ify[i];
			if((xx>=1&&xx<=fx) and (yy>=1&&yy<=fy) and b[xx][yy]==0 and txy[xx][yy]==0){
				b[xx][yx]=1;
				dfs(xx,yy);
				b[xx][yy]=0;
			}
		}
	}
}
int main(){
	cin>>n>>m>>t;
	cin>>sx>>sy>>fx>>fy;
	int tx,ty;
	for(int i=1;i<=t;i++){
		for(int j=1;j<=t;j++){
			cin>>tx>>ty;
			txy[tx][ty]=1;
		}
	}
	b[sx][sy]=1;
	dfs(sx,sy);
	cout<<ans;
	return 0;
}
2023/7/28 12:27
加载中...