洛昭君 @ 2018-05-06 19:09:39
using namespace std;
int n,m;
int ans=0;
int A[105][105];
bool mark[105][105];
void dfs(int x,int y,int sum,int high) {
ans=max(ans,sum);
for(int i=-1; i<=1; i++) {
for(int j=-1; j<=1; j++) {
if(j==0&&i==0)continue;
if(j!=0&&i!=0)continue;
if(x+i<1||x+i>n||y+j<1||y+j>m)continue;
if(mark[x+i][y+j]==1)continue;
if(A[x+i][y+j]>=high)continue;
mark[x+i][y+j]=1;
dfs(x+i,y+j,sum+1,A[x+i][y+j]);
mark[x+i][y+j]=0;
}
}
} int main() {
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
scanf("%d",&A[i][j]);
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
dfs(i,j,1,A[i][j]);
printf("%d\n",ans);
}
by strangers @ 2018-05-06 19:11:00
@zzh1902687191 您没加记忆化啊...当然会T
by Little_Jian @ 2018-05-06 19:12:38
您没加记忆化啊。。。
by 洛昭君 @ 2018-05-06 19:12:52
身为蒟蒻不会啊,@strangers
by strangers @ 2018-05-06 19:18:48
@zzh1902687191 不会就去学啊..不要明明知道哪里有错 还来发帖求助= =