/
BAEKJOON 1890
36 lines (31 loc) · 1.11 KB
/
BAEKJOON 1890
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[][] arr = new int[n + 1][n + 1];
long[][] dp = new long[n + 1][n + 1];
for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int j = 0; j < n; j++) {
arr[i][j] = Integer.parseInt(st.nextToken());
}
}
dp[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;
int next = arr[i][j];
if (i + next < n) {
dp[i + next][j] += dp[i][j];
}
if (j + next < n) {
dp[i][j + next] += dp[i][j];
}
}
}
System.out.println(dp[n-1][n-1]);
}
}