pay1234 @ 2024-07-19 10:33:37
#include<bits/stdc++.h>
using namespace std;
const int N=110;
int n,m,h[N][N],c[N][N];
int ans=0;
int xx[4]={-1,0,1,0};
int yy[4]={0,1,0,-1};
int dfs(int x,int y){
if(c[x][y]!=0) {
return c[x][y];
}
int res=1;
for(int i=0;i<4;i++){
int kx=x+xx[i];
int ky=x+yy[i];
if(kx>n ||kx<1 ||ky>m ||ky<1 ||h[kx][ky]>=h[x][y]) continue;
res=max(res,dfs(kx,ky)+1);
}
return c[x][y]=res;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>h[i][j];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
ans=max(ans,dfs(i,j));
cout<<ans;
return 0;
}
by Passerbear @ 2024-07-23 20:53:17
int ky=x+yy[i]; 错了,y写成x了。
by pay1234 @ 2024-07-24 14:15:08
非常感谢! @Passerbear