#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const int maxn = 100;
int T,n,m,sum;
int p[6][6];
int vis[6][6];
struct Point {
int x, y;
}S,F;
void printMap() {
for (int i = 1; i < 6; i++) {
for (int j = 1; j < 6; j++) {
cout << p[i][j] << " ";
}
cout << endl;
}
}
void dfs(int x, int y) {
if (x == F.x && y == F.y) {
sum++;
return;
} else if (x < 1 || y < 1 || x > m || y > n) {
return;
} else {
if (!vis[x-1][y] && !p[x-1][y]) {
vis[x][y] = 1;
dfs(x-1, y);
vis[x][y] = 0;
}
if (!vis[x+1][y] && !p[x+1][y]) {
vis[x][y] = 1;
dfs(x+1, y);
vis[x][y] = 0;
}
if (!vis[x][y-1] && !p[x][y-1]) {
vis[x][y] = 1;
dfs(x, y-1);
vis[x][y] = 0;
}
if (!vis[x][y+1] && !p[x][y+1]) {
vis[x][y] = 1;
dfs(x, y+1);
vis[x][y] = 0;
}
return;
}
}
int main() {
cin >> n >> m >> T;
cin >> S.x >> S.y >> F.x >> F.y;
while (T--) {
int x, y;
cin >> x >> y;
p[x][y] = 1;
}
dfs(S.x, S.y);
cout << sum << endl;
// printMap();
return 0;
}
P1605-迷宫(DFS)
最新推荐文章于 2023-12-27 22:22:45 发布