Under construction

Still being built. Things may change

Positioning the Lights

Time limit8sMemory limit1024 MB

Summary
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.

  1. No block of 2×22 \times 2 or larger empty squares is in the dungeon.
  2. 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

nn and mm are the number of squares in the vertical and horizontal directions, and 1≤n≤301 \le n \le 30, 1≤m≤301 \le m \le 30. Each ci,jc_{i,j} is either '#' or '.'. If it is '#', the square at row ii from the top and column jj 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 109+710^9+7, on a single line.

Examples1

  1. Example 1

    Input
    2 2
    .#
    #.
    3 3
    ...
    .#.
    ...
    2 3
    #..
    ..#
    3 3
    #.#
    ...
    #.#
    3 5
    .#.#.
    .....
    #.#.#
    0 0
    
    Expected output
    1
    161
    9
    25
    243