-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(1167)TheMaze(s).cpp
52 lines (52 loc) · 1.05 KB
/
(1167)TheMaze(s).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int total=0;
int** Creat_Arr_int(int n)
{
int** arr=(int**)malloc(n*sizeof(int*));
for(int i=0;i<n;i++)
{
arr[i]=(int*)malloc(n*sizeof(int));
}
return arr;
}
void dfs(int xR,int yR,int** list,int line)
{
if(list[xR][yR]==1)
{
return;
}
if(xR==0&&yR==line-1)
{
total++;
return;
}
list[xR][yR]=1;
if(xR>0) dfs(xR-1,yR,list,line);
if(xR<line-1) dfs(xR+1,yR,list,line);
if(yR>0) dfs(xR,yR-1,list,line);
if(yR<line-1) dfs(xR,yR+1,list,line);
if(xR>0&&yR>0) dfs(xR-1,yR-1,list,line);
if(xR>0&&yR<line-1) dfs(xR-1,yR+1,list,line);
if(xR<line-1&&yR>0) dfs(xR+1,yR-1,list,line);
if(xR<line-1&&yR<line-1) dfs(xR+1,yR+1,list,line);
list[xR][yR]=0;
}
int main()
{
int line;
scanf("%d",&line);
int** maplist=Creat_Arr_int(line);
for(int i=0;i<line;i++)
{
for(int j=0;j<line;j++)
{
scanf("%d",&maplist[i][j]);
}
}
dfs(0,0,maplist,line);
printf("%d",total);
return 0;
}