Positioning the Lights
Time limit8sMemory limit1024 MB
Count the light placements on a grid of walls and empty cells so that every empty cell is lit, modulo 10^9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Tree, Graph
- Solved
- No attempts yet
Problem
You are given a map of a dungeon made of aligned squares that form a rectangle. Each square is either a wall or an empty square. The dungeon has no open space. More specifically, it satisfies the following two conditions.
- No block of or larger empty squares is in the dungeon.
- Three or more empty squares are not diagonally aligned consecutively.

You have many lights. When you place a light on an empty square, it brightens that square and all consecutive empty squares in the four directions: up, down, left, and right. You can place at most one light on each empty square, and you can place lights on as many squares as you want.

Compute the number of possible combinations of light placements that brighten all the empty squares.
Input
The input consists of multiple datasets, each in the following format.
n m
c1,1 ... c1,m
...
cn,1 ... cn,m
and are the number of squares in the vertical and horizontal directions, and , . Each is either '#' or '.'. If it is '#', the square at row from the top and column from the left is a wall. If it is '.', the square is empty. The end of the input is a line containing two zeros. The number of datasets does not exceed 50.
Output
For each dataset, output the number of possible combinations of light placements that brighten all the empty squares, modulo , on a single line.