-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouseinmaze.cpp
More file actions
65 lines (56 loc) · 1.25 KB
/
mouseinmaze.cpp
File metadata and controls
65 lines (56 loc) · 1.25 KB
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
61
62
63
64
65
#include <bits/stdc++.h>
using namespace std;
bool issafe(int** a, int x, int y, int n){
if(a[x][y] == 1 && x<=n-1 && y<=n-1)
return true;
return false;
}
bool mim(int** a, int** s, int x, int y, int n){
if (x==n-1 && y==n-1){
s[x][y] = 1;
return true;
}
if(issafe(a,x,y,n)){
s[x][y] = 1;
if(mim(a,s,x+1,y,n))
return true;
if(mim(a,s,x,y+1,n))
return true;
s[x][y] = 0;
return false;
}
return false;
}
int main(){
int n;
cin >> n;
int** a = new int* [n];
for(int i=0; i<n; i++){
a[i] = new int [n];
for(int j=0; j<n; j++)
cin >> a[i][j];
}
int** s = new int* [n];
for(int i=0; i<n; i++){
s[i] = new int [n];
for(int j=0; j<n; j++)
s[i][j] = 0;
}
cout << "-------------------------" << endl;
if(mim(a,s,0,0,n)){
for(int i=0; i<n; i++){
for(int j=0; j<n; j++)
cout << s[i][j] << " ";
cout << endl;
}
}
else
cout << "Not possible";
return 0;
}
// 5
// 1 0 0 0 0
// 1 1 0 1 0
// 0 1 1 1 0
// 0 0 0 1 0
// 1 1 1 1 1