/*It's not difficult, but it's easy to think, but if it's memorized, it's going to kneel. We might want to use 01 maintenance next to go up or down but we ignore "each height must not be higher than the starting height" may have been recorded before the memory of the height of the current use is not the same*/#include<iostream>#include<cstdio>#include<cstring>using namespacestd;intn,m,g[ the][ the],f[ the][ the][2],ans,limit;intxx[3]={0,0,1};intyy[3]={0,1,0};intDfs (intXintYintp) { //if (f[x][y][p]!=1) return f[x][y][p]; for(intI=1; i<=2; i++) { intnx=x+Xx[i]; intny=y+Yy[i]; if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&g[nx][ny]<=limit&&(P==1&&g[nx][ny]>g[x][y]) | | (p==0&&g[nx][ny]<G[x][y]))) F[X][Y][P]=max (F[x][y][p],dfs (nx,ny,p^1)+1); } returnf[x][y][p];}intMain () {scanf ("%d%d",&n,&m); for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) {scanf ("%d",&G[i][j]); f[i][j][0]=f[i][j][1]=1; } for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) {Limit=G[i][j]; Ans=max (Ans,dfs (I,j,1)); Ans=max (Ans,dfs (I,j,0)); } printf ("%d\n", ans); return 0;}
Codevs 1958 Stimulation