Basically did not write a few search. Because from the edge into the enumeration edge of all the lattice to search, if carefully read the question must be able to know to go low ... Thought only a flat or a tall lattice also rewarded a WA. The egg hurts.
Code very rubbing + slag:
#include <iostream> #include <algorithm> #include <cstdlib> #include <sstream> #include < cstring> #include <cstdio> #include <string> #include <deque> #include <stack> #include < cmath> #include <queue> #include <set> #include <map>using namespace std;typedef long Long ll;# Define INF 0x3f3f3f3fint pos[110][110];int vis[110][110];int flag=0;int tall;int n,m;void Look (const int &x,const int &y,const int &pre) {if (x<0| | y<0| | x>=n| | y>=m| | vis[x][y]==1)//boundary + whether to access the return;vis[x][y]=1;//tag access if (pos[x][y]-pre<=1) {if (Pos[x][y]==tall) {flag=1;puts ("YES "); return;} Look (X+1,y,pos[x][y]), if (!flag) look (X-1,y,pos[x][y]), if (!flag) look (X,y+1,pos[x][y]), if (!flag) look (X,y-1,pos[x] [y]);} else{vis[x][y]=0;//Road is not accessible, not counted. return;}} int main (void) {int i,j;while (~scanf ("%d%d", &n,&m)) {memset (pos,0,sizeof (POS)); tall=-1;flag=0;for (i=0; i <n; i++) {for (j=0; j<m; J + +) {scanf ("%d", &pos[i][j]); Tall=max (Tall,pos[i][j]);}} if (tall==0) {Puts ("NO"); continue;} for (j=0; j<m; J + +) {if (pos[0][j]==1) {memset (vis,0,sizeof (VIS)); look (0,j,0);} if (flag) break;} if (!flag) {for (j=0; j<m; J + +) {if (pos[n-1][j]==1) {memset (vis,0,sizeof (VIS)); look (n-1,j,0);} if (flag) break;}} if (!flag) {for (i=0; i<n; i++) {if (pos[i][0]==1) {memset (vis,0,sizeof (VIS)), look (i,0,0);} if (flag) break;}} if (!flag) {for (i=0; i<n; i++) {if (pos[i][m-1]==1) {memset (vis,0,sizeof (VIS)), look (i,m-1,0);} if (flag) break;}} if (!flag) puts ("NO");} return 0;}
Noj--1559jump to the Top of Mountain (simple brute force dfs+ slag code)