70分求助
  • 板块P1605 迷宫
  • 楼主zs_onepice
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/5/9 19:08
  • 上次更新2024/5/9 20:48:36
查看原帖
70分求助
1165114
zs_onepice楼主2024/5/9 19:08
#include <bits/stdc++.h>
using namespace std;
int a[10][10],m,n,t,ans;
int sx,sy,fx,fy,tx,ty;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
void dfs(int x,int y){
	if(x==fx and y==fy){
		ans++;
		return;
	}
	for(int i=0;i<=3;i++){
		int nx,ny;
		nx=x+dx[i],ny=y+dy[i];
		if(nx>0 and nx<=m and ny>0 and ny<=n and a[nx][ny]==0){
			a[nx][ny]=1;
			dfs(nx,ny);
			a[nx][ny]=0; 
		}
	}
}
int main(){
	cin>>m>>n>>t;
	cin>>sx>>sy>>fx>>fy;
	for(int i=1;i<=t;i++){
		cin>>tx>>ty;
		a[tx][ty]=1;
	}
	
	dfs(sx,sy);
	cout<<ans;
	return 0;
}
2024/5/9 19:08
加载中...