50分,求助~

P1605 迷宫

但是dfs用同样的思路ac了,这是啥原因哦? ``` #include <iostream> #include <algorithm> #include <cstring> #include <map> #include <string> #include <queue> using namespace std; const int N = 6; typedef long long ll; int n, m, k; int cnt; int g[N][N]; int st[N][N]; int sx, sy, fx, fy; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; void dfs(int x, int y) { if(st[x][y]) return ; if(x == fx && fy == y) { cnt ++; return ; } for(int i = 0; i < 4; i ++) { int a = x + dx[i]; int b = y + dy[i]; if(!st[a][b] && !g[a][b] && a > 0 && a <= n && b > 0 && b <= m) { st[x][y] = true; dfs(a, b); st[x][y] = false; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; cin >> sx >> sy >> fx >> fy; for(int i = 0; i < k; i ++) { int a, b; cin >> a >> b; g[a][b] = 1; } dfs(sx, sy); cout << cnt << endl; return 0; } ```
by ssjl @ 2022-07-08 13:42:37


``` 我也是一开始用宽搜写的,哭死... 想了个半天,下载了个测试数据,发现宽搜标记之后就不会恢复了不可以像dfs,dfs可以恢复现场 ```
by mese @ 2022-07-16 09:21:21


|