-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixPaths
More file actions
26 lines (26 loc) · 778 Bytes
/
MatrixPaths
File metadata and controls
26 lines (26 loc) · 778 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
import java.util.*;
class MatrixPaths{
public static int c=0;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt(),m=sc.nextInt();
int[][] arr=new int[n][m];
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
arr[i][j]=sc.nextInt();
count(arr,0,0);
System.out.println(c);
}
public static void count(int[][] arr,int i, int j){
if(i==arr.length-1 && j==arr[0].length-1){
c++;
return;
}
if((i>=0 && i<arr.length)&& (j+1>=0 && j+1<arr[0].length)){
count(arr,i,j+1);
}
if((i+1>=0 && i+1<arr.length)&& (j>=0 && j<arr[0].length)){
count(arr,i+1,j);
}
}
}