Baseball Court
Time limit4sMemory limit1024 MB
Count the ways to place all N unit tiles in an a by b plot so each outer corner tile lies at the same Manhattan distance from the south-west corner.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
After lengthy meetings on the subject, the NCPC jury decided that getting the contestants' blood pumping would lead to better contests. So they planned a sports competition for bragging rights before the programming contest. A random draw from a hat picked baseball. What remains is building a suitable court to play on. The NCPC jury has a rectangular plot of land by meters in size. They also have square grass tiles, each by meter, which they can place on the plot to build the court. All grass tiles must be placed with their sides parallel to the edges of the plot.
The south-west corner of the land is the batting point. For the tiles to form a valid court, two conditions must hold. First, for every tile, its south and west sides must either lie directly against the edge of the plot or directly against another tile. This keeps the ball from leaving and re-entering the court along a straight trajectory. Second, every tile that has no adjacent tile to its north or east must have the same Manhattan distance from the batting point. This keeps batters from preferring some directions over others.
Find the number of ways to place the tiles so that they form a valid baseball court.
Input
The first line contains a single positive integer (), the number of grass tiles available. The second line contains two positive integers and (), the size of the land the court can be made within.
Output
Print the number of valid ways to place the grass tiles to make up a baseball court. All grass tiles must be used. Since this number might be very large, print the answer modulo .