yzc001 @ 2024-02-22 21:02:06
#include<bits/stdc++.h>
using namespace std;
int a[105][105],hs[105][105],jy[105][105],r,c,ans;
int wx[4]={1,-1,0,0};
int wy[4]={0,0,1,-1};
int dfs(int x,int y){
if(jy[x][y])return jy[x][y];
int nx,ny;
for(int i=0;i<4;i++){
nx=x+wx[i];
ny=y+wy[i];
if(hs[nx][ny]&&a[nx][ny]<a[x][y]){
jy[x][y]=max(dfs(nx,ny)+1,jy[x][y]);
}
}
return jy[x][y];
}
signed main() {
cin>>r>>c;
for(int i=1;i<=c;i++){
for(int j=1;j<=r;j++){
hs[i][j]=1;
cin>>a[i][j];
}
}
for(int i=1;i<=c;i++){
for(int j=1;j<=r;j++){
ans=max(dfs(i,j)+1,ans);
}
}
cout<<ans;
}