求助一下,感觉好像没有什么问题,直接暴力就过,但是记忆化搜索好像错了一部分

P1605 迷宫

```cpp #include <bits/stdc++.h> using namespace std; int n, m, t, sx, sy, fx, fy, step = 0; int dp[10][10] = {0}; int moves[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; int book[10][10] = {0}; int dfs(int x, int y) { if(x==fx&&y==fy) return 1; dp[x][y]=0; for (int i = 0; i < 4; i++) { int nx = x + moves[i][0]; int ny = y + moves[i][1]; if (nx < 1 || ny < 1 || nx > n || ny > m || book[nx][ny]) { continue; } book[nx][ny] = 1; dp[x][y] += dfs(nx, ny); book[nx][ny] = 0; } return dp[x][y]; } int main() { cin >> n >> m >> t >> sx >> sy >> fx >> fy; while (t--) { int p, r; cin >> p >> r; book[p][r] = 1; } book[sx][sy] = 1; dp[fx][fy] = 1; cout << dfs(sx, sy) << '\n'; return 0; } ```
by Kevin_Mamba @ 2022-10-18 17:19:26


@[ahardstone](/user/819995) 不能重复利用一个点,因为每次的情况不同 。 比如说,你在搜索到一条路径上的某个点时,你已经封锁了这条路径上前面的点 。而存储的答案,只对于这一种封锁情况有效。
by Kevin_Mamba @ 2022-10-18 17:23:07


所以动态规划是没什么必要的,直接深搜就好了 。
by Kevin_Mamba @ 2022-10-18 17:24:28


Hack : 输入 : 2 3 0 1 1 2 3 应输出 : 4 实际输出 : 3
by Kevin_Mamba @ 2022-10-18 17:27:24


@[2124Kobe](/user/576934) 感谢,hack成功上分100 :)
by ahardstone @ 2022-10-18 18:23:03


|