代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define mp(x,y) make_pair(x,y)
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
//
const int maxn = 100+10;
int n,m,mp[maxn][maxn],dp[maxn][maxn];
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int dfs(int x,int y){
if(dp[x][y]) return dp[x][y];
for(int i=0; i<4; i++){
int tx=x+dx[i],ty=y+dy[i];
if(tx<1 || tx>n || ty<1 || ty>m || mp[x][y]<=mp[tx][ty]) continue;
int tmp = dfs(tx,ty);
if(tmp >= dp[x][y]){
dp[x][y] = tmp+1;
}
}
return dp[x][y];
}
int main(){
n=read(),m=read();
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
mp[i][j] = read();
int ans = 0;
mem(dp);
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++){
int t = dfs(i,j);
if(ans < t)
ans = t;
}
cout << ans+1 << endl;
return 0;
}