#P8675. Block Stacking

    ID: 21841 Type: Default 1000ms 256MiB

Block Stacking

Block Stacking

Little Ming is fascinated by building blocks. He has many identical cubic blocks. First, he uses m blocks to form a continuous foundation (layer 0) by placing them in a row without gaps. Then, he may build up to n additional layers (layers 1 through n) on top of the foundation following these rules:

  1. Each block in layer i (for i ≥ 1) must be placed directly above some block in layer i - 1, aligned perfectly.
  2. Blocks in the same layer must form a contiguous segment (i.e. there cannot be any gaps between them).
  3. Blocks cannot be placed at positions that Ming dislikes. These forbidden positions are marked on a drawing consisting of n rows. The first row (bottom row) corresponds to layer 1, the second to layer 2, and so on up to layer n. Each row is a string of m characters, where a dot (.) indicates an allowed position and an X indicates a forbidden one.

Even if no block is placed on top of the foundation, that configuration is counted as a valid scheme. Compute the number of valid stacking schemes modulo \(10^9+7\).

inputFormat

The first line contains two integers m and n, representing the number of blocks in the foundation and the maximum number of layers to be built, respectively. The following n lines describe the drawing from layer 1 to layer n (from bottom to top). Each of these lines is a string of length m consisting only of the characters . and X.

outputFormat

Output a single integer, the number of valid stacking schemes modulo \(10^9+7\).

sample

3 1
...
7

</p>