#include <iostream> #include <cstring> using namespace std; int n,m,map[110][110]; //int dir[4][2]={-1,0,0,-1,0,1,1,0}; int dfs(int x,int y){ if(map[x][y]>map[x-1][y]&&map[x][y]>map[x][y-1]&&map[x][y]>map[x][y+1]&&map[x][y]>map[x+1][y]) return 0; int maxn=0; if(map[x][y]>map[x-1][y]) maxn=max(maxn,dfs(x-1,y)+1); if(map[x][y]>map[x][y-1]) maxn=max(maxn,dfs(x,y-1)+1); if(map[x][y]>map[x][y+1]) maxn=max(maxn,dfs(x,y+1)+1); if(map[x][y]>map[x+1][y]) maxn=max(maxn,dfs(x+1,y)+1); return maxn; } int main(){ while(cin>>n>>m){ int ans=0; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin>>map[i][j]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) ans=max(dfs(i,j),ans); cout<<ans<<endl; memset(map,0,sizeof(map)); } return 0; } |
Double click to view unformatted code.