liujiazhi @ 2025-01-01 17:05:49
rt
#include<bits/stdc++.h>
using namespace std;
int z[105][105],ans[105][105];
pair<int,int> q[10005];
bool F(pair<int,int> x,pair<int,int> y)
{
return x.first<=y.first;
}
int main()
{
int n,r,c,i,j,p=0,maxn=0;
cin>>r>>c;
n=r*c;
for (i=1;i<=r;i++)
{
for (j=1;j<=c;j++)
{
cin>>z[i][j];
q[++p].first=z[i][j];
q[p].second=i*c-c+j;
}
}
sort(q+1,q+n+1,F);
for (i=1;i<=n;i++)
{
int a,b,s;
s=q[i].second;
b=s%c;
if (b==0) b=c;
a=(s-b)/c+1;
if (z[a-1][b]<z[a][b]) ans[a][b]=max(ans[a][b],ans[a-1][b]);
if (z[a+1][b]<z[a][b]) ans[a][b]=max(ans[a][b],ans[a+1][b]);
if (z[a][b-1]<z[a][b]) ans[a][b]=max(ans[a][b],ans[a][b-1]);
if (z[a][b+1]<z[a][b]) ans[a][b]=max(ans[a][b],ans[a][b+1]);
ans[a][b]++;
}
for (i=1;i<=r;i++)
{
for (j=1;j<=c;j++)
{
maxn=max(maxn,ans[i][j]);
}
}
cout<<maxn;
return 0;
}
by SH1ARK @ 2025-01-09 12:34:01
maxn的值应该设定为1