题解
2024-06-29 22:48:11
发布于:广东
11阅读
0回复
0点赞
深搜
#include <iostream>
#include <cstdio>
using namespace std;
int a[6][6];//我嘞个大唐盛世这么浓缩的迷宫
bool vis[6][6];
int dir[4][2] = {-1, 0, 0, -1, 0, 1, 1, 0};
int n, m, t, x1, y1, x2, y2, x, y;
bool check(int x, int y){
if(x < 1 || x > n) return 0;
if(y < 1 || y > m) return 0;
if(vis[x][y]) return 0;
return 1;
}
int dfs(int x, int y){
if(x == x2 && y == y2) return 1;
int ct = 0;
vis[x][y] = 1;
for(int i = 0; i < 4; i++){
int xx = x + dir[i][0], yy = y + dir[i][1];
if(check(xx, yy)) ct += dfs(xx, yy);
}
vis[x][y] = 0;
return ct;
}
int main(){
cin >> n >> m >> t >> x1 >> y1 >> x2 >> y2;
while(t--){
cin >> x >> y;
vis[x][y] = 1;
}
cout << dfs(x1, y1);
return 0;
}
这里空空如也
有帮助,赞一个