#include<bits/stdc++.h>
using namespace std;
int read() {
int s = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
s = s * 10 + c - '0';
c = getchar();
}
return s * w;
}
void print(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x >= 10)
print(x / 10);
putchar(x % 10 + '0');
return;
}
#define fro(n) for(int i=1;i<=n;i++)
#define ofr(n) for(int i=1;i<=n;i++)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
const double eps = 1e-6;
const int maxn = 1e8;
const int mod = 1e6+7;
const int INF = 0x3f3f3f3f;
const int maxsize = 105;
LL dp[maxsize][maxsize];
struct node{
LL x,y;
LL value;
friend bool operator < (node x,node y){
return x.value > y.value;
}
}a[maxsize][maxsize];
priority_queue <node> p;
void solve();
bool check(int x);
void dfs(int x,int y);
bool cmp(node x,node y);
int main(){
LL T = 1;
while(T--){
LL ans = 0;
int n = read(),m= read();
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
a[i][j].value = read();
a[i][j].x = i;
a[i][j].y = j;
p.push(a[i][j]);
}
}
while(!p.empty()){
node start = p.top();
if(a[start.x][start.y].value > a[start.x - 1][start.y].value){
dp[start.x][start.y] = max(dp[start.x][start.y],dp[start.x - 1][start.y] + 1);
}
if(a[start.x][start.y].value > a[start.x + 1][start.y].value){
dp[start.x][start.y] = max(dp[start.x][start.y],dp[start.x + 1][start.y] + 1);
}
if(a[start.x][start.y].value > a[start.x][start.y - 1].value){
dp[start.x][start.y] = max(dp[start.x][start.y],dp[start.x][start.y - 1] + 1);
}
if(a[start.x][start.y].value > a[start.x][start.y + 1].value){
dp[start.x][start.y] = max(dp[start.x][start.y],dp[start.x][start.y + 1] + 1);
}
ans = max(ans,dp[start.x][start.y]);
p.pop();
}
print(ans);
}
return 0;
}
提交记录,题目P1434。