AC代码
#include <bits/stdc++.h>
using namespace std;
#define ms(a,b) memset(a,b,sizeof(a))
typedef long long ll;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int vis[105][105], a[105][105];
int r, c;
int f[105][105];
inline int read()
{
int X=0,w=0; char ch=0;
while(!isdigit(ch))
{
w|=ch=='-';
ch=getchar();
}
while(isdigit(ch))
{
X=(X<<3)+(X<<1)+(ch^48);
ch=getchar();
}
return w?-X:X;
}
int dfs( int x, int y )
{
if ( f[x][y] ) return f[x][y] ;
int tmp=1;
for (int i= 0; i < 4; i++)
{
int nx = x + dx[i], ny = y + dy[i];
if (nx<1 || nx>r || ny<1 || ny>c) continue;
if (a[x][y] < a[nx][ny] ) tmp = max( dfs( nx, ny)+1, tmp);
}
return f[x][y] = tmp;
}
int main(int argc,char* argv[])
{
ms ( f , 0);
r=read(),c=read();
for (int i=1; i<=r; i++)
{
for (int j=1; j<=c; j++) a[i][j]= read(), vis[i][j]= 0;
}
int ans = 0;
for (int i= 1; i<= r; i++)
{
for (int j= 1; j<= c; j++)
{
f[i][j] = dfs( i, j);
ans = max( f[i][j], ans);
}
}
printf ("%d\n", ans);
return 0;
}