提交时间:2024-03-30 15:54:19

运行 ID: 140567

#include<bits/stdc++.h> #define int long long using namespace std; int a[105][105],dp[105][105],n,m,o[5][3] = {{-1,0},{1,0},{0,-1},{0,1}}; struct P{ int x,y; }; int dfs(int cx,int cy){ if (dp[cx][cy] != 0){ return dp[cx][cy]; } for (int i = 0;i < 4;i++){ int sx = cx + o[i][0],sy = cy + o[i][1]; if (sx <= 0 || sx > n || sy <= 0 || sy > m){ continue; } if (a[sx][sy] >= a[cx][cy]){ continue; } dp[cx][cy] = max(dp[cx][cy],dfs(sx,sy) + 1); } if (dp[cx][cy] == 0){ dp[cx][cy] = 1; } return dp[cx][cy]; } signed 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++){ //dp[i][j] = max(dp[i][j],1LL); dfs(i,j); } } int ans = 1; for (int i = 1;i <= n;i++){ for (int j = 1;j <= m;j++){ //cout<<dp[i][j]<<' '; ans = max(ans,dp[i][j]); } //cout<<'\n'; } cout<<ans; return 0; }