Three-way Branch
Time limit7sMemory limit64 MB
Count three-way downward paths from (1,1) to (W,H) on a grid with up to 30 blocked cells, modulo 1000000009.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Matrix
- Solved
- No attempts yet
Problem
There is a grid of columns and rows. The upper left cell is : the first coordinate grows to the right and the second coordinate grows downward. You stand on and you want to reach .
From cell you may move only to the cell below and to the left , the cell directly below , or the cell below and to the right .
Some cells hold an obstruction. You cannot move onto an obstructed cell, and you cannot leave the grid. Write a program that prints the number of paths reaching , modulo 1,000,000,009. The cell never holds an obstruction.
Input
The input holds several test cases.
The first line of each test case has the width , the height , and the number of obstructions , separated by spaces. (, , )
Each of the next lines has the position , of one obstruction. (, )
The line after the last test case holds three zeros.
Output
For each test case, print one line with the case number and the number of paths reaching , modulo 1,000,000,009. If the answer of the -th test case is , print it in the form Case k: a.