POJ - 1088
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define ll long long
#define maxn 150
int mmp[maxn][maxn],r,c,sum,ans;
int book[maxn][maxn];
int to[5][3]= {{0,1},{0,-1},{1,0},{-1,0}};
bool judge(int x,int y)
{
if(x<0||y<0||x>r-1||y>c-1)
return false;
return true;
}
int dfs(int x,int y)
{
if(book[x][y]==1)
{
for(int i=0; i<4; i++)
{
int tx=x+to[i][0];
int ty=y+to[i][1];
if(judge(tx,ty))
{
if(mmp[tx][ty]>=mmp[x][y])continue;
book[x][y]=max(book[x][y],dfs(tx,ty));
}
}
}
return book[x][y]+1;
}
int main()
{
scanf("%d%d",&r,&c);
for(int i=0; i<r; i++)
for(int j=0; j<c; j++)
{
scanf("%d",&mmp[i][j]);
book[i][j]=1;
}
ans=0;
for(int i=0; i<r; i++)
for(int j=0; j<c; j++)
{
ans=max(ans,dfs(i,j));
}
printf("%d\n",ans-1);
return 0;
}