aiyougege @ 2018-04-10 22:01:50
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
#define N 105
int n,m;
int dx[10]={0,0,-1,1};
int dy[10]={1,-1,0,0};
struct Point{
int x,y,c;
bool operator<(const Point& s)const{
return c>s.c;
}
}p[N*N];
int tot;
int pos[N][N];
int f[N][N];
int main(){
scanf("%d%d",&n,&m);int tmp;
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j){
scanf("%d",&tmp);
p[++tot]=(Point){i,j,tmp};
pos[i][j]=tmp;
}
sort(p+1,p+tot+1);int ans=0;
for(int i=1;i<=tot;++i){
int x=p[i].x,y=p[i].y;
f[x][y]=max(f[x][y],1);
for(int i=0;i<4;++i){
int xx=x+dx[i],yy=y+dy[i];
if(pos[xx][yy]>=pos[xx][yy])continue;
f[xx][yy]=max(f[xx][yy],f[x][y]+1);
ans=max(ans,f[xx][yy]);
}
}
if(ans==0)ans=1;
printf("%d",ans-1);
return 0;
}