Transmission Door
Yesterday saw this question thought is a brain remnant dp, but the brain is the remnant of me.
The title means to go from the upper left corner to the lower right corner, set X as the maximum value on the path-the minimum value, and the minimum value of x.
Two x, for each X, enumeration of the nether lower, lower starting from 0 enumeration, each time the BFS, if a point value is less than lower or greater than lower+x, then do not go this point, see finally can go to the end.
I can't bear to look straight at the two-part writing of my own integers ... Changed for a long time.
1#include <bits/stdc++.h>2 using namespacestd;3 #definePB (x) push_back (x)4 #definell Long Long5 #defineMK (x, y) make_pair (x, y)6 #defineLson L, M, rt<<17 #defineMem (a) memset (a, 0, sizeof (a))8 #defineRson m+1, R, rt<<1|19 #defineMem1 (a) memset (a,-1, sizeof (a))Ten #defineMEM2 (a) memset (a, 0x3f, sizeof (a)) One #defineRep (I, A, n) for (int i = A; i<n; i++) A #defineull unsigned long Long -typedef pair<int,int>PLL; - Const DoublePI = ACOs (-1.0); the Const DoubleEPS = 1e-8; - Const intMoD = 1e9+7; - Const intINF =1061109567; - Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} }; + inta[ Max][ Max], vis[ -][ -], N; - intBinintLowerintUpper) { +Queue <pll>Q; A mem (VIS); at if(a[0][0]<lower| | a[0][0]>Upper) - return 0; -Q.push (MK (0,0)); -vis[0][0] =1; - while(!Q.empty ()) { -PLL tmp =Q.front (); Q.pop (); in intx =Tmp.first; - inty =Tmp.second; to if(x = = n1&& y = = n1) + return 1; - for(inti =0; i<4; i++) { the intTMPX = x+dir[i][0]; * intTmpy = y+dir[i][1]; $ if(tmpx>=0&&tmpx<n&&tmpy>=0&&tmpy<n&&!Vis[tmpx][tmpy]) {Panax NotoginsengVis[tmpx][tmpy] =1; - if(a[tmpx][tmpy]<=upper&&a[tmpx][tmpy]>=Lower) the Q.push (Mk (TMPX, tmpy)); + } A } the } + return 0; - } $ intCheckintval) { $ for(inti =0; i+val<= the; i++) { - if(Bin (I, i+val)) - return 1; the } - return 0;Wuyi } the intMain () - { Wu while(cin>>N) { - for(inti =0; i<n; i++) { About for(intj =0; j<n; J + +) { $scanf"%d", &a[i][j]); - } - } - intL =0, r = the; A while(r>l) { + intm = l+r>>1; the if(check (m)) { -R =m; $}Else { theL = m+1; the } the } thecout<<l<<Endl; - } in}
POJ 2110 Mountain Walking Two-point +bfs