How many paths?

Consider an n × m matrix where each cell (i, j) has a number x_(ij) to
indicate that you can jump down to a distance (measured as number of
cells) between 1 and x_(ij), either vertically, diagonally to the left,
or diagonally to the right. If we call (0, 0) the upper left position,
all the visited cells must have coordinates between 0 and n for the rows
(this includes a row below the last one), and between 0 and m − 1 for
the columns. The goal is to start at row 0, and get exactly to row n.
How many paths exist?

Input

Input consists of several cases, each with n, m, and n rows with m
natural numbers. Suppose that n, m and the x_(ij) are between 1 and 100.

Output

For every case, print the number of paths that begin at any cell in the
top row and end in any cell just below the bottom row, modulo 10⁹ + 7.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T12:03:17.263Z

© Jutge.org, 2006–2026.
https://jutge.org
