#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
const int maxn=100+10;
using namespace std;
struct node{
int w,x,y;
bool operator < (const node &b) const{
return this->w<b.w;
}
}node[maxn*maxn];
int p[maxn][maxn],f[maxn][maxn];
int main()
{
int r,c,cnt=0,ans=1;
scanf("%d%d",&r,&c);
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
scanf("%d",&p[i][j]);
f[i][j]=1;
node[cnt].w=p[i][j];
node[cnt].x=i;
node[cnt].y=j;
cnt++;
}
}
sort(node,node+cnt);
for(int i=cnt-1;i>0;i--)
{
int x=node[i].x,y=node[i].y;
if(x+1<=r&&p[x+1][y]<p[x][y]) {f[x+1][y]=max(f[x+1][y],f[x][y]+1);ans=max(ans,f[x+1][y]);}
if(y+1<=c&&p[x][y+1]<p[x][y]) {f[x][y+1]=max(f[x][y+1],f[x][y]+1);ans=max(ans,f[x][y+1]);}
if(x-1>=1&&p[x-1][y]<p[x][y]) {f[x-1][y]=max(f[x-1][y],f[x][y]+1);ans=max(ans,f[x-1][y]);}
if(y-1>=1&&p[x][y-1]<p[x][y]) {f[x][y-1]=max(f[x][y-1],f[x][y]+1);ans=max(ans,f[x][y-1]);}
}
printf("%d\n",ans);
return 0;
}
百练 1088 滑雪
最新推荐文章于 2021-04-08 16:55:31 发布