可以参考一下
  • 板块P1605 迷宫
  • 楼主liaozichun
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/8/6 15:27
  • 上次更新2024/8/6 15:39:13
查看原帖
可以参考一下
1247610
liaozichun楼主2024/8/6 15:27
#include<bits/stdc++.h>
using namespace std;
long long n,m,stx,sty,ex,ey,t;
long long mp[100][100];
long long ans;
void dfs(long long x,long long y){
	if(x == ex and y == ey){
		ans++;
		return;
	}
	if(x - 1 >= 1 and mp[x - 1][y] != -1){
		mp[x][y] = -1;
		dfs(x - 1,y);
		mp[x - 1][y] = 0;
	}
	if(x + 1 <= n and mp[x + 1][y] != -1){
		mp[x][y] = -1;
		dfs(x + 1,y);
		mp[x + 1][y] = 0;
	}
	if(y + 1 <= m and mp[x][y + 1] != -1){
		mp[x][y] = -1;
		dfs(x,y + 1);
		mp[x][y + 1] = 0;
	}
	if(y - 1 >= 1 and mp[x][y - 1] != -1){
		mp[x][y] = -1;
		dfs(x,y - 1);
		mp[x][y - 1] = 0;
	}
	return;
}
int main(){
	cin>>n>>m>>t;
	cin>>stx>>sty>>ex>>ey;
	long long x,y;
	while(t--){
		cin>>x>>y;
		mp[x][y] = -1;
	}
	dfs(stx,sty);
	cout<<ans;
	return 0;
}

可以参考一下

2024/8/6 15:27
加载中...