-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_possible_path_exists.cpp
More file actions
69 lines (44 loc) · 906 Bytes
/
Copy pathcheck_possible_path_exists.cpp
File metadata and controls
69 lines (44 loc) · 906 Bytes
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
66
67
68
69
#include"essentials.cpp"
bool check_possible_path(int maze[5][5]){
maze[0][0]=1;
for(int i=1;i<5;i++){
if(maze[0][i]!=-1){
maze[0][i]=maze[0][i-1];
}
}
for(int i=1;i<5;i++){
if(maze[i][0]!=-1){
maze[i][0]=maze[i-1][0];
}
}
for(int i=1;i<5;i++){
for(int j=1;j<5;j++){
if(maze[i][j]!=-1){
maze[i][j]=max(maze[i-1][j],maze[i][j-1]);
}
}
}
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
cout<<maze[i][j]<<" ";
}
cout<<endl;
}
if(maze[4][4]==-1){
return false;
}
else{
return true;
}
}
int main(){
int maze[5][5]={
{ 0, 0, 0, -1, 0},
{-1, 0, 0, -1, -1},
{ 0, 0, 0, -1, 0},
{-1, 0, -1, 0, 0},
{ 0, 0, -1, 0, 0}
};
cout<<check_possible_path(maze);
return 1;
}