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
| #include <iostream> #include <vector> #include <string> using namespace std;
void dfs(int N, int M, int x, int y, int z, int w, int height, long & count, vector<vector<int> >& map, vector<vector<bool> > &visited){ if (x < 0 || y < 0 || x >= N || y >= M || map[x][y] <= height || visited[x][y]) { return; }
if (x == z && y == w) { count++; return; } visited[x][y] = true; dfs(N, M, x - 1, y, z, w, map[x][y], count, map, visited); dfs(N, M, x, y - 1, z, w, map[x][y], count, map, visited); dfs(N, M, x + 1, y, z, w, map[x][y], count, map, visited); dfs(N, M, x, y + 1, z, w, map[x][y], count, map, visited); visited[x][y] = false; }
int main() { int N, M, X, Y, Z, W; cin >> N >> M; vector<vector<int> > map(N, vector<int>(M)); vector<vector<bool> > visited(N, vector<bool>(M)); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { int tmp; cin >> tmp; map[i][j] = tmp; } } cin >> X >> Y >> Z >> W; long count = 0; dfs(N, M, X, Y, Z, W, -1, count, map, visited); cout << count % 1000000000 << endl; return 0; }
|