poj 1088

include

include

include

using namespace std;

define MAX_N 110

int r, c;
int map[MAX_N][MAX_N];
int dx[4] = {1, 0, -1, 0}, dy[4]= {0, 1, 0, -1};
int len[MAX_N][MAX_N];

int dp(int a, int b) {
int x, y, s;
int ms = 0;
if (len[a][b] != 0) return len[a][b];

for (int i = 0; i < 4; i++) {
    x = a + dx[i];
    y = b + dy[i];
    if (x < 0 || y < 0 || x > r - 1 || y > c - 1) continue;
    if(map[x][y] < map[a][b]) {
        s = dp(x, y);
        ms = max(ms, s);
    }
}
len[a][b] = ms + 1;
return len[a][b];

}

int main() {
cin >> r >> c;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> map[i][j];
}
}
memset(len,0,sizeof(len));
int Max = -1;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
Max=max(Max,dp(i,j));
}
}
cout << Max << endl;
return 0;
}

你可能感兴趣的:(poj 1088)