我用DFS写的,但是只能得到70分,在#2 #7 #8中WA了。我该怎么改???
#include <bits/stdc++.h>
using namespace std;
typedef long long l;
l n, m, t, ans;
l sx, sy, fx, fy;
bool ways[10][10];
l t1, t2;
l dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, -1, 1};
void dfs(l x, l y) {
if (x == fx && y == fy) {
ans ++;
return;
}
l tx, ty;
for (int i = 0; i < 4; i ++) {
tx = x + dx[i], ty = y + dy[i];
if (ways[tx][ty]) {
ways[tx][ty] = false;
dfs(tx, ty);
ways[tx][ty] = true;
}
}
}
int main () {
cin >> n >> m >> t;
cin >> sx >> sy >> fx >> fy;
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= m; j ++) {
ways[i][j] = true;
}
}
for (int i = 0; i < t; i ++) {
cin >> t1 >> t2;
ways[t1][t2] = false;
}
dfs(sx, sy);
cout << ans << endl;
return 0;
}