代码如下:
#include <cstdio>
#include <algorithm>
#include <cstring>
#define maxn 105
using namespace std;
int dx[4] = { 1, -1, 0, 0}, dy[4] = { 0, 0, 1, -1}, r, c, dp[maxn][maxn] = {0}, a[maxn][maxn];
int search( int x, int y){
if ( dp[x][y]){
return dp[x][y];
}
dp[x][y] = 1;
for ( int k = 0; k < 4; k++){
int tx = x + dx[k], ty = y + dy[k];
if ( tx > 0 && tx <= r && ty > 0 && ty <= c && a[x][y] > a[tx][ty]){
dp[x][y] = max( dp[x][y], search( tx, ty) + 1);
}
}
return dp[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", &a[i][j]);
}
}
int m = 1;
for ( int i = 1; i <= r; i++){
for ( int j = 1; j <= c; j++){
m = max( m, search( i, j));
}
}
printf( "%d\n", m);
return 0;
}