ColinKIA @ 2022-06-18 12:16:54
#include <bits/stdc++.h>
using namespace std;
int n,m,a[105][105],dp[105][105];
bool vis[105][105];
void dfs(int x,int y,int step,int sx,int sy){
if(vis[x+1][y]==0&&x+1<=n&&a[x+1][y]<a[x][y]){
if(dp[x+1][y]!=0){
vis[x+1][y]=1;
dp[sx][sy]=max(step+dp[x+1][y],dp[sx][sy]);
return ;
}else{
vis[x+1][y]=1;
dfs(x+1,y,step+1,sx,sy);
vis[x+1][y]=0;
}
}
if(vis[x-1][y]==0&&x-1>=1&&a[x-1][y]<a[x][y]){
if(dp[x-1][y]!=0){
vis[x-1][y]=1;
dp[sx][sy]=max(step+dp[x-1][y],dp[sx][sy]);
return ;
}else{
vis[x-1][y]=1;
dfs(x-1,y,step+1,sx,sy);
vis[x-1][y]=0;
}
}
if(vis[x][y-1]==0&&y-1>=1&&a[x][y-1]<a[x][y]){
if(dp[x][y-1]!=0){
vis[x][y-1]=1;
dp[sx][sy]=max(step+dp[x][y-1],dp[sx][sy]);
return ;
}else{
vis[x][y-1]=1;
dfs(x,y-1,step+1,sx,sy);
vis[x][y-1]=0;
}
}
if(vis[x][y+1]==0&&y+1<=m&&a[x][y+1]<a[x][y]){
if(dp[x][y+1]!=0){
vis[x][y+1]=1;
dp[sx][sy]=max(step+dp[x][y+1],dp[sx][sy]);
return ;
}else{
vis[x][y+1]=1;
dfs(x,y+1,step+1,sx,sy);
vis[x][y+1]=0;
}
}
dp[sx][sy]=max(step,dp[sx][sy]);
return ;
}
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++){
dfs(i,j,1,i,j);
}
}
int ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ans=max(dp[i][j],ans);
}
}
cout<<ans;
}
求调,1 2 9错了