挺模板化的遍历,范围也很小,直接爆搜
对于这种方格不能重复经过的题目,就是for方向 + dfs搜索即可
// Problem: P1605 迷宫
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1605
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// Date: 2024-03-27 21:57:20
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define endl '\n'
#define int int64_t
#define ld long double
using namespace std;
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
const int NC = 2e3 + 10;
//char ches[NC][NC];
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
int a[N], b[N], n, m, k, sx, sy, fx, fy, ans;
int ches[10][10], vis[10][10];
void dfs(int x, int y) {
if (x == fx && y == fy) {
ans++;
return;
}
vis[x][y] = 1;
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 1 || nx > n || ny < 1 || ny > m)continue;
if (!vis[nx][ny] && !ches[nx][ny]) {
dfs(nx, ny);
}
}
vis[x][y] = 0;
}
void solve() {
cin >> n >> m >> k;
cin >> sx >> sy >> fx >> fy;
while (k--) {
int x, y; cin >> x >> y;
ches[x][y] = 1;
}
dfs(sx, sy);
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}