#P6275. [USACO20OPEN] Sprinklers 2: Return of the Alfalfa P
[USACO20OPEN] Sprinklers 2: Return of the Alfalfa P
Problem Description
Farmer John has a small field shaped like an by grid. For all , the cell in the -th row from top to bottom and the -th column from left to right is denoted . He is interested in planting sweet corn and alfalfa in his field. To do so, he needs to install some special sprinklers.
A sweet corn sprinkler in cell can water all cells to its lower-left, i.e., all such that and .
An alfalfa sprinkler in cell can water all cells to its upper-right, i.e., all such that and .
A cell watered by one or more sweet corn sprinklers can grow sweet corn; a cell watered by one or more alfalfa sprinklers can grow alfalfa. However, a cell watered by both types of sprinklers (or by neither type) cannot grow anything.
Help Farmer John compute the number of ways to install sprinklers in his field ( ). At most one sprinkler may be installed in each cell, and every cell must be able to grow a crop (i.e., be watered by exactly one type of sprinkler).
Some cells are occupied by hairy cows; this does not prevent those cells from growing crops, but sprinklers cannot be installed in those cells.
Input Format
The first line contains an integer .
For each , the -th line contains a string of length , describing the -th row of the grid. Each character is either W (a cell occupied by a hairy cow) or . (unoccupied).
Output Format
Output the number of ways to install sprinklers, modulo .
2
..
..
28
4
..W.
..WW
WW..
...W
2304
Hint
Explanation for Sample :
Below are all ways that make grow sweet corn. (Translator's note: C means sweet corn; A means alfalfa.)
CC .C CA CC .C CA CA C. CA C. CC .C CC .C
CC, CC, CC, .C, .C, .C, CA, CA, .A, .A, C., C., .., ..
Notes for Sample :
This sample satisfies the constraints of the first subtask.
For of the testdata, .
There are test points. Points are the samples, and the rest have the following properties:
For test points , and there are at most unoccupied cells.
For test points , .
For test points , there are no special constraints.
Problem author: Benjamin Qi
Translated by ChatGPT 5