#include <cstdio> #include <iostream> using namespace std; int mmap[100][100]={0}; int max(int t,int l,int r,int b){ int maxs=t; if(maxs<l) maxs=l; if(maxs<r) maxs=r; if(maxs<b) maxs=b; return maxs; } int digui(int i,int j,int curent){ int t=0,l=0,r=0,b=0; int top,left,right,bottom; top=mmap[i-1][j]; left=mmap[i][j-1]; right=mmap[i][j+1]; bottom=mmap[i+1][j]; if(top>curent){ t=digui(i-1,j,top)+1; } if(left>curent){ l= digui(i,j-1,left)+1; } if(right>curent){ r= digui(i,j+1,right)+1; } if(bottom>curent){ b=digui(i+1,j,bottom)+1; } return max(t,l,r,b); } int main(){ int n,m; while(cin>>n>>m){ for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>mmap[i][j]; } } int maxs=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ int res=digui(i,j,mmap[i][j]); if(maxs<res) maxs=res; } } cout<<maxs<<endl; } return 0; } |
Double click to view unformatted code.