Luo Gu P1605 maze depth search templates!

Topic background

Given an N * M squares maze, T-maze at the barrier, not through the barrier. Given the start point and end point, Q: After a maximum of 1 per box, how many from the start point to the end point coordinate coordinates the program. In the maze to move up and down about four ways, you can only move one square. No obstacles to ensure data starting point.

Title Description

no

Input Format

The first row N, M and T, N row, M being a column, T is the total number of disorders. The second line starting coordinates SX, SY, ending coordinate FX, FY. Then the coordinates of the point T lines, each behavioral disorders.

Output Format

Given the start point and end point, and asked after each square up to 1 times the total number of programs from the starting point to the end point coordinate coordinates.

Sample input and output

Input # 1
2 2 1
1 1 2 2
1 2
Output # 1
1

Description / Tips

[Data] scale

1≤N,M≤5

 

 

Code

#include <the iostream>
#include <cstdio>
the using namespace STD;
BOOL G [15] [15], VIS [15] [15];    // G is the total map, VIS whether to access the recording
int n, m, d [5 ] = {-1,0,1,0, -1};      // direction
int NX, NY, EX, EY, the CNT;
            // NX, NY starting coordinates; ex, ey end point coordinates, the CNT path Article number
void dfs (int X, Y int) {
 IF (X == Y == && EX EY) {      // If the end point to
  the CNT ++;          // add a path to
  return;        // continue to look back on a return
 }
 for (int K = 0; K <. 4; K ++) {
  int L = X + D [K];
  int R & lt = Y + D [K +. 1];
  IF (L> =. 1 && R & lt> =. 1 && L <= n-&& R & lt <= m && G [L] [! ! R & lt] && VIS [L] [R & lt]) {      // Note starting
   VIS [L] [R & lt] = to true;              // marked as visited
   dfs (l, r);
   REGULAR [l] [r] = false;            // back
  }
 }
 return;                         // return a lookup to continue or not if on a proper path, continue to return           
}
int main () {
 int T, ZX, ZY;
 CIN >> >> m >> n-T> > NX NY >> >> >> EX EY;
 G [NX] [NY] = to true;
 the while (T--) {
  CIN >> >> ZX ZY;
  G [ZX] [ZY] = to true;            // set disorder
 }
 DFS (NX, NY);          // looking from the start
 COUT << the CNT;
 return 0;
}
 
Apply a template depth search
 
Supplementary: C language there is no bool (Boolean) type, which have C ++, that is to say, the use of bool type in C ++ there is no problem. bool type has only two values: true = 1, false = 0

Guess you like

Origin www.cnblogs.com/QingyuYYYYY/p/11618499.html