#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 NN by NN grid. For all 1i,jN1 \le i,j \le N, the cell in the ii-th row from top to bottom and the jj-th column from left to right is denoted (i,j)(i,j). 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 (I,J)(I,J) can water all cells to its lower-left, i.e., all (i,j)(i,j) such that IiI \le i and jJj \le J.

An alfalfa sprinkler in cell (I,J)(I,J) can water all cells to its upper-right, i.e., all (i,j)(i,j) such that iIi \le I and JjJ \le j.

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 ( mod 109+7\bmod \ 10^9 + 7). 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 NN.
For each 1iN1\le i\le N, the (i+1)(i+1)-th line contains a string of length NN, describing the ii-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 109+710^9+7.

2
..
..
28
4
..W.
..WW
WW..
...W
2304

Hint

Explanation for Sample 11:

Below are all 1414 ways that make (1,1)(1,1) 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 22:

This sample satisfies the constraints of the first subtask.


For 100%100\% of the testdata, 1N20001 \le N \le 2000.

There are 1616 test points. Points 121 \sim 2 are the samples, and the rest have the following properties:

For test points 343 \sim 4, N10N \le 10 and there are at most 1010 unoccupied cells.
For test points 595 \sim 9, N200N \le 200.
For test points 101610 \sim 16, there are no special constraints.


Problem author: Benjamin Qi

Translated by ChatGPT 5