1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| #include<iostream> #include<string.h> using namespace std; int r=0,c=0,ans=0; int map[105][105],longest[105][105],height[105][105]; int dx[5]={-1,0,1,0}; int dy[5]={0,1,0,-1}; int search(int x,int y){ if(longest[x][y]<0){ int maxLength=0; for(int i=0;i<4;i++){ int nx=x+dx[i]; int ny=y+dy[i]; if(nx>=0 && nx<=r && ny>=0 && ny<=c && map[x][y]<map[nx][ny]){ int nextLength=search(nx,ny); if(maxLength<nextLength){ maxLength=nextLength; } } } longest[x][y]=maxLength+1; } return longest[x][y]; } int main(){ memset(map,0,sizeof(map)); memset(longest,-1,sizeof(longest)); memset(height,0,sizeof(height)); cin>>r>>c; for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ cin>>map[i][j]; } } for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ if(ans<search(i,j)){ ans=search(i,j); } } } cout<<ans<<endl; return 0; }
|