#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
int x,y;
int tot=1,sum[10001]={0},ans=0;
struct data
{
int x,y,h;
}a[10001];
bool cmp(data a,data b)
{
return a.h>b.h;
}
bool check(int i,int j)
{
int k;
for(k=0;k<=3;k++)
{
if(a[i].x+dx[k]==a[j].x && a[i].y+dy[k]==a[j].y)
{
return true;
}
}
return false;
}
int main()
{
int i=0,j=0;
cin>>x>>y;
for(i=1;i<=x;i++)
{
for(j=1;j<=y;j++)
{
cin>>a[tot].h;
a[tot].x=i;
a[tot].y=j;
tot++;
}
}
sort(a+1,a+1+tot,cmp);
for(i=1;i<=tot;i++)
{
sum[i]=1;
for (j=i-1;j>0;j--)
{
if (check(i,j)&&a[j].h>a[i].h)
sum[i]=max(sum[i],sum[j]+1);
}
}
ans=0;
for(i=1;i<=tot;i++)
{
ans=max(ans,sum[i]);
}
cout<<ans<<endl;
return 0;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步