20分DFS
  • 板块P1605 迷宫
  • 楼主152chenzihao
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/2/2 10:36
  • 上次更新2023/10/24 02:06:28
查看原帖
20分DFS
638371
152chenzihao楼主2023/2/2 10:36
#include<bits/stdc++.h>
using namespace std;

int n,m,t,lh,ll,tot;
int sx,sy,fx,fy;
bool a[6][6];
int xx[5]={0,1,1,-1,-1};
int yy[5]={0,-1,1,1,-1};

void dfs(int h,int l){
	if(h==fx&&l==fy){
		tot++;
		return;
	}
//	cout<<h<<" "<<l<<endl;
	for(int i=1;i<=4;i++){
		if(a[h+xx[i]][l+yy[i]]||h+xx[i]>n||h+xx[i]<1||l+yy[i]>m||l+yy[i]<1) continue;
		a[h][l]=true;
		dfs(h+xx[i],l+yy[i]);
		a[h][l]=false;
	}
}

int main(){
	cin>>n>>m>>t;
	cin>>sx>>sy>>fx>>fy;
	for(int i=1;i<=t;i++){
		cin>>lh>>ll;
		a[lh][ll]=true;
	}
	dfs(sx,sy);
	cout<<tot;
	return 0;
}
2023/2/2 10:36
加载中...