-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rate In Maze.cpp
60 lines (46 loc) · 994 Bytes
/
Rate In Maze.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
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
int c=0;
void maze(vector<vector<int>>& a,vector<vector<int>>& sol,int n,int x,int y)
{
if(x==n-1 && y==n-1)
{
sol[x][y]=1;
c++;
cout<<"SOLUTION:"<<endl; //Printing All possible paths
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<sol[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<endl;
return;
}
if(x>=n || x<0 || y>=n || y<0 || sol[x][y]==1 || a[x][y]==1)
return;
sol[x][y]=1;
maze(a,sol,n,x-1,y);
maze(a,sol,n,x,y-1);
maze(a,sol,n,x+1,y);
maze(a,sol,n,x,y+1);
sol[x][y]=0;
}
int main() {
int n,i,j;
cin>>n;
vector<vector<int>> a(n,vector<int>(n,0));
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
vector<vector<int>> sol(n,vector<int>(n,0));
maze(a,sol,n,0,0);
cout<<c<<endl;
return 0;
}