40分求助
  • 板块P1605 迷宫
  • 楼主OIYu
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/8/11 19:15
  • 上次更新2024/8/11 20:26:06
查看原帖
40分求助
1413253
OIYu楼主2024/8/11 19:15
#include<bits/stdc++.h>
using namespace std;
int n,m,t;
int sx,sy,fx,fy;
int x[15],y[15];
int xy[15][15];
int ans;
int a[4]={0,0,-1,1};
int b[4]={-1,1,0,0};
bool judge(int x,int y){
	if(x<1||x>n||y<1||y>m||xy[x][y]==1)return 1;
	return 0;
}
void dfs(int x,int y){
	if(x==fx&&y==fy){
		ans++;
		return;
	}
	for(int i=0;i<4;i++){
		int xx=x+a[i];
		int yy=y+b[i];
		if(judge(xx,yy))continue;
		xy[xx][yy]=1;
		dfs(xx,yy);
	}
}
int main(){
	cin>>n>>m>>t;
	cin>>sx>>sy>>fx>>fy;
	for(int i=1;i<=t;i++){
		cin>>x[i]>>y[i];
		xy[x[i]][y[i]]=1;
	}
	xy[sx][sy]=1;
	dfs(sx,sy);
	cout<<ans;
	return 0;
}

2024/8/11 19:15
加载中...