Substitute0329 @ 2019-01-12 16:24:09
#include<bits/stdc++.h>
using namespace std;
int mp[1001][1001],n,m,f[1001][1001];
inline int max(int x,int y){return x>y?x:y;}
inline int read(){
register int x=0;
register char c=getchar();
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x;
}
inline void write(int x){
if(x<0)x=-x,putchar(45);
if(x)write(x/10);
else return ;
putchar(x%10+48);
return ;
}
inline int dfs(register int x,register int y){
if(f[x][y]!=1)return f[x][y];
int res=0;
if(x+1<=n&&mp[x+1][y]<mp[x][y])res=max(res,dfs(x+1,y)+1);
if(x-1>=1&&mp[x-1][y]<mp[x][y])res=max(res,dfs(x-1,y)+1);
if(y+1<=m&&mp[x][y+1]<mp[x][y])res=max(res,dfs(x,y+1)+1);
if(y-1>=1&&mp[x][y-1]<mp[x][y])res=max(res,dfs(x,y-1)+1);
return max(f[x][y],res);
}
int main(){
n=read();m=read();
for(register int i=1;i<=n;i++){
for(register int j=1;j<=m;j++)
mp[i][j]=read(),f[i][j]=1;
}
register int ans=0;
for(register int i=1;i<=n;i++){
for(register int j=1;j<=m;j++)
ans=max(ans,dfs(i,j));
}
write(ans);
return 0;
}
by CRAEF @ 2019-01-12 16:41:07
下数据试试
by Substitute0329 @ 2019-01-12 17:21:54
@轩轩718 额……