Baltic Olympiad in Informatics: 2006 Day 2, Problem 3
An game board is populated with integers, one non-negative integer per square. The goal is to jump along any legitimate path from the upper left corner to the lower right corner of the board. The integer in any one square dictates how large a step away from that location must be. If the step size would advance travel off the game board, then a step in that particular direction is forbidden. All steps must be either to the right or toward the bottom. Note that a is a dead end which prevents any further progress.
Consider the board shown in Figure 1, where the solid circle identifies the start position and the dashed circle identifies the target. Figure 2 shows the three legitimate paths from the start to the target, with the irrelevant numbers in each removed.
Your task is to write a program that determines the number of legitimate paths from the upper left corner to the lower right corner.
Constraints
In test cases worth of points, the answer will fit within a -bit integer.
It is guaranteed that all inputs will lead to an answer of no more than digits.
Input Specification
The first line of input contains an integer , which is the number of rows in this board. This is followed by rows of data. Each row contains integers, each one in the range .
Output Specification
Output a single integer: the number of legitimate paths from the upper left corner to the lower right corner.
Sample Input
4
2 3 3 1
1 2 1 3
1 2 3 1
3 1 1 0
Sample Output
3
Comments