#Q173. 「一本通 5.4 例 2」牧场的安排
「一本通 5.4 例 2」牧场的安排
Description
Original Source: USACO 2006 Nov. Gold
Farmer John has recently purchased a new rectangular pasture, which is divided into rows and columns . Each cell is a square plot of land. FJ plans to plant delicious grass in some of these plots for his cows to enjoy. Unfortunately, some of the land is quite barren and cannot be used for grazing. Additionally, cows prefer to have exclusive access to a grassy area, so FJ will not select two adjacent plots—meaning no two grassy plots share a common edge. Of course, FJ has not yet decided which plots to plant with grass.
As a curious farmer, FJ wants to know how many different planting schemes are available to him, without considering the total number of grassy plots. Leaving the entire pasture unused (i.e., planting no grass at all) also counts as one valid scheme. Please help FJ calculate this total number of schemes.
Input Format
Line : Two positive integers and , separated by a space;
Lines to : Each line contains space-separated integers describing the state of each plot. The -th line describes the plots in the -th row. All integers are either or , where indicates the plot is fertile enough, and means the plot is unsuitable for planting grass.
Output Format
Line : Output an integer, which is the total number of pasture allocation schemes modulo .
Sample 1
Label the plots as shown below:
1 2 3
0 4 0
There are schemes for planting grass in a single plot: choosing any one of or . For planting grass in two plots, there are schemes: , and . There is only one scheme for planting grass in three plots: . Adding the option of leaving the pasture unused, the total number of schemes is .
2 3
1 1 1
0 1 0
9
Constraints and Hints
.