#P7642. [BalticOI 2006] JUMP THE BOARD! (Day 2)

    ID: 8509 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP2006BalticOI(波罗的海)

[BalticOI 2006] JUMP THE BOARD! (Day 2)

Problem Description

An n×nn \times n game board is filled with integers, one non-negative integer in each cell. The goal is to jump from the top-left corner to the bottom-right corner along any valid path. The integer in any cell gives the jump length when leaving that cell. If a jump length would move you outside the board, then the jump in that specific direction is forbidden. All jumps must be either to the right or downward. Note that 00 is a dead end and prevents any further progress.

As shown in Figure 11, on the 4×44 \times 4 board, the solid circle marks the start position and the dashed circle marks the target position. Figure 22 shows three valid paths from the start to the target, and in each path the irrelevant numbers are removed.
TuLi

Your task is to write a program to determine the number of valid paths from the top-left corner to the bottom-right corner.

Input Format

The first line contains a positive integer nn, the number of rows and columns of the board. The next nn lines follow. Each line contains nn integers, and each integer is in the range 090 \cdots 9.

Output Format

The only line contains one integer, the number of valid paths from the top-left corner to the bottom-right corner.

4
2 3 3 1
1 2 1 3
1 2 3 1
3 1 1 0
3

Hint

Constraints

  • For 100%100\% of the testdata, 4n1004 \le n \le 100.
  • The number of valid paths can be quite large. Using a 6464-bit integer variable (in C, long long int, in Pascal, Int64) can only get 70%70\% of the score. It is guaranteed that for all inputs, the number of paths can be written with no more than 100100 digits.

Notes

The problem comes from Baltic Olympiad in Informatics 2006 Day 2: Jump.
Translated and organized by @求学的企鹅.

Translated by ChatGPT 5