When a person is skiing down, the longest length of skiing is required.
Idea: d [I] [J] = max {DP [I-1] [J] + 1, DP [I + 1] [J] + 1, DP [I] [J-1] + 1, DP [I] [J + 1] + 1}, of course to meet some basic conditions: high and low. here is the use of memory-based search
AC program:
# Include <iostream> # include <stdio. h> # include <string. h> using namespace STD; int map [105] [105]; int dir [4] [2] = {-}, {}, {0}, {0, -1}, {105}; int d [105] []; int n, m; int DFS (int A, int B) {int ans = d [a] [B]; If (ANS> 0) return ans; ans = 1; for (INT I = 0; I <4; I ++) {int Tx = a + dir [I] [0]; int ty = B + dir [I] [1]; if (TX> = 0 & TX <n & ty> = 0 & ty <m) {If (Map [a] [B]> map [TX] [ty]) {int TMP = DFS (TX, Ty) + 1; if (ANS <TMP) ans = TMP ;}}return ans ;}int main () {CIN >>n> m; For (INT I = 0; I <n; I ++) for (Int J = 0; j <m; j ++) {CIN> map [I] [J];} memset (D, 0, sizeof (d )); int max =-1; for (INT I = 0; I <n; I ++) for (Int J = 0; j <m; j ++) {int TMP = DFS (I, j); D [I] [J] = TMP; If (TMP> MAX) max = TMP ;}cout <max <Endl; // system ("pause"); Return 0 ;}