PDP-32 (2020) - Camp common - 1 (countways)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem type
Allowed languages
C, C++, Java, Pascal, Python

How many ways;

We are given a chessboard with N \times M squares. Each square contains a number. We start from the top-left square and want to reach the bottom-right square. In each move, we can only move one square up, down, left, or right and only under the condition that the square we move to has a strictly larger number than the square we are currently on. How many different ways can we reach from the top-left square to the bottom-right square?

(We consider two paths to be different if the sequences of coordinates of the squares they pass through are different.)

Input:

The first line of the input will contain two positive integers N and M, separated by a space: the dimensions of the chessboard. Each of the next N lines will contain M positive integers separated in pairs by a space: the numbers written on the squares of the chessboard, in the obvious order.

Output:

The output should consist of a single line containing exactly one integer: the number of ways to reach from the top-left square to the bottom-right square. Since this number can be very large, print the remainder of its division (modulo) by 10^9 + 7.

Constraints:
  • 1 \le N \le 1.000
  • 1 \le M \le 1.000
  • The numbers in the squares of the chessboard will not exceed 1.000.000.000.
  • Time Limit: 1 sec.
  • Memory Limit: 128 MB.
  • For test cases with a total value of 30%, it will be N \le 10 and M \le 10.
  • For test cases with a total value of 50%, it will be N \le 100 and M \le 100.
Example of Input - Ouput:

input:

5 5
17 23 26 30 31
21 10 19 32 32
24 24 54 34 33
25 32 37 38 35
26 27 80 40 42

output:

6
Explanation of the example:

There are six ways to go from the top-left square (17) to the bottom-right (42), always moving to squares with progressively larger numbers. One way is along the first row and then the last column: 17 \to 23 \to 26 \to 30 \to 31 \to 32 \to 33 \to 35 \to 42. Another way is: 17 \to 21 \to 24 \to 25 \to 26 \to 27 \to 32 \to 37 \to 38 \to 40 \to 42. There are four other ways that you should look for and find.


Comments

There are no comments at the moment.