Board Jump
InterviewTime limit1sMemory limit128 MB
Count distinct paths from top-left to bottom-right of an N×N grid where each cell's digit fixes the exact jump length right or down, using big-integer DP.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Matrix, Math
- Solved
- No attempts yet
Problem
You are given an N × N game board. Each cell holds a single digit from 0 to 9. A piece starts on the top-left cell and must reach the bottom-right cell.
The number written in a cell is the exact distance (jump length) you must move from that cell. You may only move to the right or downward, and you must move exactly that many cells to the right or exactly that many cells down. A cell containing 0 is a terminal cell from which no further move is possible.
Count the number of distinct paths that start at the top-left cell and reach the bottom-right cell while following these rules.
Input
The first line contains an integer N (4 ≤ N ≤ 100). Each of the next N lines contains N digits between 0 and 9, separated by spaces.
Output
Print, on a single line, the number of distinct paths from the top-left cell to the bottom-right cell that follow the rules. The number of paths may exceed , but it never has more than 100 digits.

