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
| #include <bits/stdc++.h> using namespace std; const int R = 301, C = 301; int r, c, res; int m[R][C], step[R][C]; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int search(int x, int y) { if(step[x][y] != -1) return step[x][y]; step[x][y] = 1; for(int i = 0; i < 4; ++i) { int xx = x + dx[i], yy = y + dy[i]; if(xx >= 1 && xx <= r && yy >= 1 && yy <= c && m[x][y] > m[xx][yy]) { step[x][y] = max(step[x][y], search(xx, yy)+1); } } return step[x][y]; }
int main() { scanf("%d%d", &r, &c); for(int i = 1; i <= r; ++i) { for(int j = 1; j <= c; ++j) { scanf("%d", &m[i][j]); } }
memset(step, -1, sizeof step); for(int i = 1; i <= r; ++i) { for(int j = 1; j <= c; ++j) res = max(res, search(i, j)); } printf("%d", res); return 0; }
|