Count subsets of empty cells in an R x C grid, modulo 1e9+7, such that every row has a scarecrow and every pair of consecutive columns has one.
Hard8Dynamic programmingBit manipulationCombinatoricsMatrixNo attempts yetTime limit2sMemory limit512 MBNerissa owns a rectangular paddy field of size R×C. The field is divided into R rows and C columns of equal square cells. Each cell is either empty soil that can hold a scarecrow or soil already planted with rice.
To keep birds such as crows and sparrows away from the crops, Nerissa wants to place scarecrows on the field. A scarecrow can stand only on an empty cell. To keep other people from stealing the crops, the placement must be sacred. A placement is sacred when it satisfies both conditions below:
Two placements differ when some cell holds a scarecrow in exactly one of them. Count the distinct sacred placements.
The first line contains two integers R and C (1≤R≤14, 1≤C≤1000), the number of rows and the number of columns. The next R lines describe the field. Each line contains a string of length C. Each cell is written as . for empty soil or v for soil planted with rice.
Print the number of distinct sacred placements on one line. The number can be very large, so print it modulo 1,000,000,007.
In the second sample case, 5 placements satisfy both conditions. With one row of three empty cells, 5 nonempty subsets cover both adjacent column pairs.
In the third sample case, the first row has no cell that can hold a scarecrow. Since every row needs at least one scarecrow, no sacred placement exists.
In the fifth sample case, 5 placements satisfy both conditions. The empty cells of the two rows are offset, so the row requirement and the column pair requirement together leave 5 possibilities.