dfs-- maze

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.

Vis to open a record point is passed, if not gone, and left point, the vis updated to 1, to continue the search, update and then back to 0 for the next use.

Four combinations dir1 and dir2 a dot after the four directions and determine whether or not to go out of bounds

. 1 #include <the iostream>
 2 #include <the cstdlib>
 . 3 #include <cstdio>
 . 4 #include <the cmath>
 . 5  the using  namespace STD;
 . 6  int Map [ . 6 ] [ . 6 ]; // map; 
. 7  BOOL VIS [ . 6 ] [ 6 ]; // through indicia; 
. 8  int DX [ . 4 ] = { 0 , 0 , . 1 , - . 1 };
 . 9  int Dy [ . 4 ] = {- . 1 , . 1,0,0};
10 int total,fx,fy,sx,sy,T,n,m,l,r;
11 void dfs(int x,int y)
12 {
13     if(x==fx&&y==fy)
14     {
15         total++;
16         return;
17     }
18     else
19     {
20         for(int i=0;i<=3;i++)
21         {
22             if(vis[x+dx[i]][y+dy[i]]==0&&map[x+dx[i]][y+dy[i]]==1)
23             {
24                 vis[x][y]=1;
25                 dfs(x+dx[i],y+dy[i]);
26                 vis[x][y]=0;
27             }    
28         } 
29     }
30 }
31 int main()
32 {
33     cin>>n>>m>>T;
34     for(int i=1;i<=n;i++)
35         for(int j=1;j<=m;j++)
36             map[i][j]=1;
37     scanf ("%d%d",&sx,&sy);
38    scanf ("%d%d",&fx,&fy); 
39     for(int u=1;u<=T;u++)
40     {
41         scanf("%d%d",&l,&r);
42         map[l][r]=0;
43     }
44     dfs(sx,sy);
45     cout<<total;
46     return 0;
47 } 

 

Guess you like

Origin www.cnblogs.com/very-beginning/p/11761874.html