谁能帮帮本蒟蒻啊!!!
  • 板块P1605 迷宫
  • 楼主Jason_yinkai
  • 当前回复15
  • 已保存回复15
  • 发布时间2021/8/6 15:34
  • 上次更新2023/11/4 11:49:10
查看原帖
谁能帮帮本蒟蒻啊!!!
406170
Jason_yinkai楼主2021/8/6 15:34

这是测试点

这是代码:

#include<iostream>
using namespace std;
int map[100][100];
int vis[100][100];
int dx[5] = {0,0,0,1,-1};
int dy[5] = {0,1,-1,0,0};
int n,m,t,sx,sy,fx,fy;
void dfs(int x,int y){
	if(x == fx and y == fy){
		map[fx][fy] += 1;
	}
	for(int i = 1;i <= 4;i++){
		int next_x = x + dx[i];
		int next_y = y + dy[i];
		if(map[next_x][next_y] != -1 and vis[next_x][next_y] != 1 and x >= 1 and y >= 1 and next_x <= n and next_y <= m){
			vis[next_x][next_y] = 1;
			dfs(next_x,next_y);
			vis[next_x][next_y] = 0;
		}
	}
}
int main(){
	cin>>n>>m>>t;
	cin>>sx>>sy>>fx>>fy;
	for(int i = 1;i <= t;i++){
		int tx,ty;
		cin>>tx>>ty;
		map[tx][ty] = -1;
	}
	dfs(sx,sy);
	cout<<map[fx][fy];
}
救救小学生吧
2021/8/6 15:34
加载中...