-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1890.java
More file actions
49 lines (39 loc) · 1.18 KB
/
1890.java
File metadata and controls
49 lines (39 loc) · 1.18 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
import java.util.*;
import java.io.*;
public class Main{
static int max=0;
static int m;
static int n;
static int count = 0;
static int[][] map;
static long[][] check;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
m = Integer.parseInt(br.readLine());
map = new int[m+1][m+1];
check = new long[m+1][m+1];
for(int i=1; i<=m; i++){
StringTokenizer str = new StringTokenizer(br.readLine());
for(int j=1; j<=m; j++){
map[i][j] = Integer.parseInt(str.nextToken());
}
}
check[1][1]=1;
dp(1, 1);
System.out.println(check[m][m]);
}
private static void dp(int startX, int startY){
int num=0;
for(int i=startX; i<=m;i++){
for(int j=startY; j<=m; j++){
num = map[i][j];
if(i+num<=m && num !=0){
check[i+num][j] +=check[i][j];
}
if(j+num<=m && num !=0){
check[i][j+num] +=check[i][j];
}
}
}
}
}