Mouse Journey
InterviewTime limit2sMemory limit512 MB
Count monotone right/down paths on an R by C grid from (1,1) to (R,C) that avoid K blocked cat cells.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Matrix, Combinatorics
- Solved
- No attempts yet
Problem
You are a mouse living in a cage in a large laboratory. The laboratory consists of a rectangular grid of square cages with rows and columns in total ().
For exercise, the laboratory owners let you move between cages. You may move only to the adjacent cage immediately to the right in the same row, or to the adjacent cage immediately below in the same column. You cannot move diagonally, left, or up.
Your cage sits in one corner of the laboratory, labeled (top-most row, left-most column). You want to visit your brother, who lives in the cage labeled (bottom-most row, right-most column) in the diagonally opposite corner. However, some cages contain cats and cannot be passed through.
Your brother, who loves numbers, wants to know how many different paths there are from your cage to his that never pass through a cat cage. Write a program that computes the number of cat-free paths.
Input
The first line contains two integers and , separated by a single space, giving the number of rows and columns respectively. The second line contains the integer , the number of cages that contain cats. Each of the next lines contains the row and column position (in that order) of a cage that contains a cat. None of the cat cages are repeated, and all of them are valid positions. Also, and are never cat cages.
Output
Output a single non-negative integer: the number of paths from your cage at to your brother's cage at . You may assume the answer is strictly less than 1,000,000,000.