70求助

P1605 迷宫

@[万灭、蓝鲸](/user/351081) ans++后面要return;
by ⚡zhangjingcan⚡ @ 2021-01-01 18:34:20


@[⚡zhangjingcan⚡](/user/219661) 试过了还是只有70 ```cpp #include <bits/stdc++.h> //#pragma GCC optimize(2) using namespace std; int dx[5] = {0, -1, 0, 1, 0}; int dy[5] = {0, 0, 1, 0, -1}; int n, m, t, sx, sy, ex, ey, ans, a[15][15]; int read() { int sum = 0, w = 1; char ch = getchar(); while (ch != '-' && !isdigit(ch)) ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while(isdigit(ch)) sum = (sum << 3) + (sum << 1) + ch - '0', ch = getchar(); return sum * w; } void dfs(int x, int y) { if (x == ex && y == ey) { ans++; return; } else for (int i = 1; i <= 4; i++) { int tx = x + dx[i]; int ty = y + dy[i]; if (a[tx][ty] == 0) { a[tx][ty] = -1; dfs(tx, ty); a[tx][ty] = 0; } } } int main() { memset(a, -1, sizeof(a)); n = read(), m = read(), t = read(); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) a[i][j] = 0; sx = read(), sy = read(), ex = read(), ey = read(); for (int i = 1; i <= t; i++) a[read()][read()] = -1; dfs(sx, sy); cout << ans << endl; return 0; } ```
by 万灭、蓝鲸 @ 2021-01-01 18:35:42


@[万灭、蓝鲸](/user/351081) 在开头加个a[x][y]=-1
by ⚡zhangjingcan⚡ @ 2021-01-01 18:42:09


|