-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrat.java
More file actions
39 lines (35 loc) · 798 Bytes
/
rat.java
File metadata and controls
39 lines (35 loc) · 798 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
import java.util.*;
class rat{
static x[] = {0,1};
static y[] = {1,0};
static void solve(int[][] m,int row,int col){
if(row==m && col==n) {
int c = 0;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(m[i][j] == true)
c++;
}
}
System.out.println(c);
return;
}
else{
for(int i=0;i<2;i++){
int n_i = row+x[i];
int n_j = col+y[i];
if(isSafe(m,n_i,n_j))
maze[n_i][n_j] = true;
}
}
}
public static void main(String[] args){
Scanner s = new Scanner(System.in);
//Maze size
int m = s.nextInt();
int n = s.nextInt();
//rat current location is (0,0) and has to reach (m-1,n-1)
boolean maze[][] = new boolean[m][n];
solve(maze,0,0);
}
}