Tray Bien
Time limit1sMemory limit256 MB
Count the ways to cover a 3 by m shelf with blocked cells using 1 by 1 and domino trays, where only the domino pairings distinguish arrangements.
- Level
Medium6 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
André Claude Marzipan is the head chef at the French restaurant Le Chaud Chien. He owns a great many baking trays, and they come in only two sizes, 1 foot × 1 foot and 1 foot × 2 feet. He stores them on shelves that are always 3 feet deep and vary in length. On a shelf 5 feet long, for example, he might store trays in either of the two ways shown below.

Figure G.1
There are many more ways than these two. André is un maniaque du rangement (a neat freak), so he always aligns the trays with the two axes given by the shelf edges, keeps every tray edge a whole number of feet from any shelf edge, and never lets a tray stick out past the shelf. A shelf feet long is therefore a grid of 1 foot squares with 3 rows and columns, and one tray covers either a single square or two squares that share an edge.
The matter is complicated by spots on the shelf where he does not want to put a tray, because of a leak above the shelf, a dent in the surface, and so on. A square that holds such a spot must be left empty, and every other square must be covered by exactly one tray. Trays of the same size are interchangeable, so two arrangements are different exactly when they pair squares into 1 × 2 trays differently.
André is more adept at cuisine than at counting. Find the number of ways the trays can be placed on the shelf.
Input
The first line contains two integers and . Here () is the length of the shelf, which is always 3 feet deep, and is the number of bad locations on the shelf.
The second line contains the coordinate pairs of the locations where trays must not be placed. Every pair satisfies and , no coordinate is an integer, and coordinates are given to the nearest hundredth. If , the second line is empty.
Output
Print the number of ways the trays can be placed on the shelf. The answer fits in a signed 64-bit integer.