abcaawtq @ 2023-09-23 23:21:47
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int a[N][N],f[N][N];
int dx[4] = {1,-1,0,0},dy[4] = {0,0,1,-1};
int n,m,ans = 0,maxn = 0;
int dfs(int x,int y){
if(f[x][y]) return f[x][y];
f[x][y] = 1;
for(int i = 0; i < 4; i ++){
int xx = x + dx[i],yy = y + dy[i];
if(xx <= n && yy <= m && xx > 0 && yy > 0 && a[xx][yy] < a[x][y]){
dfs(xx,yy);
f[x][y] = max(f[x][x],f[xx][yy] + 1);
}
}
return f[x][y];
}
int main(){
cin >> n >> m ;
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
cin >> a[i][j];
}
}
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
ans = max(ans,dfs(i,j));
}
}
cout << ans ;
return 0;
}
by lwwwb_555 @ 2023-09-23 23:32:44
14行应该是: f[x][y]=max(f[x][y],f[xx][yy]+1)吧
by abcaawtq @ 2023-09-24 08:27:18
@lwwwb_555 谢谢 AC了