#C7061. Robot Delivery Paths

    ID: 50891 Type: Default 1000ms 256MiB

Robot Delivery Paths

Robot Delivery Paths

The problem is to determine the number of distinct paths a robot can take from the top-left corner of a grid to a set of specified delivery locations. The robot can only move either right or down at each step.

Given a grid of size N rows and M columns, and a list of delivery coordinates (using 0-indexing), compute, for each coordinate, the number of unique paths from the starting cell (0, 0) to the destination cell. The number of ways to reach the cell at coordinate \( (x,y) \) is equivalent to the binomial coefficient \( \binom{x+y}{x} \) (or \( \binom{x+y}{y} \)). You are required to implement a solution based on dynamic programming.

Example:
For a 3x3 grid with deliveries at (2, 2), (1, 2) and (2, 1), the corresponding number of paths are 6, 3 and 3 respectively.

inputFormat

The input is read from standard input and is formatted as follows:

  1. The first line contains three integers: N (number of rows), M (number of columns), and K (the number of delivery locations).
  2. Each of the following K lines contains two space-separated integers x and y, representing a delivery coordinate. The coordinates are 0-indexed.

outputFormat

For each delivery location, output the number of distinct paths from the top-left corner (0, 0) to that location. The outputs should be printed on separate lines on standard output.

## sample
3 3 3
2 2
1 2
2 1
6

3 3

</p>