zhangchengyi356535 @ 2023-05-04 21:12:25
#include <bits/stdc++.h>
using namespace std;
int n,m,mapp[110][110];
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};
int ans=1,flag,maxx,minn=1e9;
struct nod{
int x,y,t;
};
queue<nod>q;
int bfs(int x,int y){
nod st;
st.t=1; st.x=x; st.y=y;
q.push(st);
while(q.empty()==0){
nod now=q.front(); q.pop();
for(int i=0;i<4;i++){
nod nxt;
nxt.x=now.x+dx[i]; nxt.y=now.y+dy[i];
if(nxt.x>=1&&nxt.x<=n&&nxt.y>=1&&nxt.y<=m&&mapp[nxt.x][nxt.y]<mapp[now.x][now.y]){
nxt.t=now.t+1;
ans=max(ans,nxt.t);
q.push(nxt);
}
}
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>mapp[i][j];
maxx=max(maxx,mapp[i][j]);
minn=min(minn,mapp[i][j]);
}
}
for(int i=n;i>=1;i--){
for(int j=m;j>=1;j--){
bfs(i,j);
if(ans==maxx-minn+1){
cout<<ans<<endl;
return 0;
}
}
}
cout<<ans<<endl;
return 0;
}
by zhangchengyi356535 @ 2023-05-04 21:28:25
楼主自己是煞笔,不会用记搜,此帖到此结束