-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathRateinamaze.cpp
53 lines (40 loc) · 878 Bytes
/
Rateinamaze.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
/*
Name: Mehul Chaturvedi
IIT-Guwahati
*/
#include<bits/stdc++.h>
using namespace std;
void printSolution(int** solution,int n){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout << solution[i][j] << " ";
}
}
cout<<endl;
}
void mazeHelp(int maze[][20],int n,int** solution,int x,int y){
if(x == n-1 && y == n-1){
solution[x][y] =1;
printSolution(solution,n);
solution[x][y] =0;
return;
}
if(x>=n || x<0 || y>=n || y<0 || maze[x][y] ==0 || solution[x][y] ==1){
return;
}
solution[x][y] = 1;
mazeHelp(maze,n,solution,x-1,y);
mazeHelp(maze,n,solution,x+1,y);
mazeHelp(maze,n,solution,x,y-1);
mazeHelp(maze,n,solution,x,y+1);
solution[x][y] = 0;
}
void ratInAMaze(int maze[][20], int n){
int** solution = new int*[n];
for(int i=0;i<n;i++){
solution[i] = new int[n];
}
mazeHelp(maze,n,solution,0,0);
}
int main(){
}