40分求助
  • 板块P1605 迷宫
  • 楼主NERDS
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/10/20 21:48
  • 上次更新2023/10/27 06:43:41
查看原帖
40分求助
566035
NERDS楼主2022/10/20 21:48
#include<bits/stdc++.h>
using namespace std;
const int N=10;
int sx,sy,fx,fy,cnt;
bool vis[N][N];
int n,m,t;
void dfs(int x,int y){
	if(x==fx&&y==fy){
		cnt++;
		return;
	}
	if(x<=0||x>n||y<=0||y>m)return;
	if(vis[x][y])return;
	vis[x][y]=1;
	dfs(x+1,y);
	dfs(x-1,y);
	dfs(x,y+1);
	dfs(x,y-1);
}
int main(){
	cin>>n>>m>>t;
	cin>>sx>>sy>>fx>>fy;
	int x,y;
	for(int i=1;i<=t;i++){
		cin>>x>>y;
		vis[x][y]=1;
	}
	dfs(sx,sy);
	cout<<cnt<<endl; 
	return 0;
} 
2022/10/20 21:48
加载中...