
Java 코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[][] board = new int[N][N];
long[][] dp = new long[N][N];
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int j = 0; j < N; j++) {
board[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 (dp[i][j] != 0 && board[i][j] != 0) {
int next = board[i][j];
if (i + next < N) { // 다음 이동 위치가 범위 안에 있는 경우
dp[i + next][j] += dp[i][j];
}
if (j + next < N) {
dp[i][j + next] += dp[i][j];
}
}
}
}
// 인덱스는 0부터 시작이니 N에서 -1씩 해준다.
System.out.println(dp[N - 1][N - 1]);
}
}