1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #include <iostream> #include <cstdio> #include <cstring> using namespace std;
bool vis[6 + 2][6 + 2]; int mp[6 + 2][6 + 2];
const int dx[4] = {0, 0, 1, -1}; const int dy[4] = {-1, 1, 0, 0};
int tot, endx, endy, stx, sty, n, m, t;
void dfs(int x, int y) { if (x == endx && y == endy) { ++tot; return; } for (int i = 0; i < 4; ++i) { int nowx = x + dx[i]; int nowy = y + dy[i]; if (!vis[nowx][nowy] && mp[nowx][nowy]) { vis[nowx][nowy] = true; dfs(nowx, nowy); vis[nowx][nowy] = false; } } }
int main(int argc, char *const argv[]) { cin >> n >> m >> t; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { mp[i][j] = (int) true; } } cin >> stx >> sty; cin >> endx >> endy; for (int i = 1; i <= t; ++i) { int l, r; cin >> l >> r; mp[l][r] = false; } vis[stx][sty] = true; dfs(stx, sty); cout << tot << endl; return 0; }
|