linyuhuai @ 2021-05-02 12:16:35
#include<bits/stdc++.h>
using namespace std;
int a[5005][5005];
int f[1005][1005];
int fx[5]= {0,1,-1,0,0};
int fy[5]= {0,0,0,1,-1};
int n,m;
int dfs(int x,int y) {
if(f[x][y]!=0) {
return f[x][y];
}
f[x][y]=1;
for(int b=1; b<=4; b++) {
int xx=fx[b]+x;
int yy=fy[b]+y;
if(a[xx][yy]<a[x][y]&&xx>0&&xx<=n&&yy>0&&yy<=m) {
dfs(xx,yy);
f[x][y]=max(f[x][y],f[xx][yy]+1);
}
}
return f[x][y];
}
int main() {
int n,m;
cin>>n>>m;
for(int b=1; b<=n; b++) {
for(int i=1; i<=m; i++) {
cin>>a[b][i];
}
}
int ans=0;
for(int b=1; b<=n; b++) {
for(int i=1; i<=m; i++) {
ans=max(ans,dfs(b,i));
}
}
cout<<ans;
}
by endless_loop @ 2021-05-02 13:01:13
好家伙,你 main 函数里声明 n,m
by endless_loop @ 2021-05-02 13:03:43
@linyuhuai 你 dfs 里用的还是全局的
by linyuhuai @ 2021-05-02 13:07:31
谢谢大佬,过了,Orz