-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
42 lines (35 loc) · 1.04 KB
/
Main.java
File metadata and controls
42 lines (35 loc) · 1.04 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
import java.util.Scanner;
public class Main {
static int[][] arr;
static int N;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
N = scanner.nextInt();
arr = new int[N][N];
long[][] answer = new long[N][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
arr[i][j] = scanner.nextInt();
}
}
answer[0][0] = 1;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i == N - 1 && j == N - 1) {
continue;
}
if (answer[i][j] == 0) {
continue;
}
int now = arr[i][j];
if (i + now < N) {
answer[i + now][j] += answer[i][j];
}
if (j + now < N) {
answer[i][j + now] += answer[i][j];
}
}
}
System.out.println(answer[N - 1][N - 1]);
}
}