

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
縦 マス、横 マスのグリッドがあります。
上から 行目、左から 列目のマス は、 が #
のとき壁であり、.
のとき道です。
マス にチェスのクイーンの駒が置いてあります。 クイーンの駒は、今いる位置から右・下・右下方向に伸びる直線上にあり、壁を飛び越えずに到達できる道のマスに 手で移動することができます。
クイーンの駒がマス からマス まで移動する方法は何通りありますか? で求めてください。
ただし、移動する方法が異なるとは、ある が存在して、 手目の移動の後にクイーンの駒があるマスの位置が異なることを指します。
制約
- は
#
か.
- と は
.
入力
入力は以下の形式で標準入力から与えられる。
出力
クイーンの駒がマス から まで移動する方法の数を で出力せよ。
入力例 1Copy
3 3 ... .#. ...
出力例 1Copy
10
移動方法として次の 通りが考えられます。
入力例 2Copy
4 4 ...# .... ..#. ....
出力例 2Copy
84
からは 手で のいずれかへ移動することが出来ます。
への移動経路として、例えば などがあります。
入力例 3Copy
8 10 .......... .......... .......... .......... .......... .......... .......... ..........
出力例 3Copy
13701937
移動方法の数を で求めてください。
Score : points
Problem Statement
We have a grid with horizontal rows and vertical columns of squares.
Square , which is at the -th row from the top and -th column from the left, is wall if is #
and road if is .
.
There is a queen, the chess piece, at Square . In one move, it can move any number of squares to the right, downwards, or diagonally to the lower right to a road square without jumping over wall squares.
In how many ways can the queen travel from Square to Square ? Find the count modulo .
Here, two ways to travel are considered different if and only if there exists such that the position of the queen after the -th move is different in those two ways.
Constraints
- is
#
or.
. - and are
.
.
Input
Input is given from Standard Input in the following format:
Output
Print the number of ways, modulo , in which the queen can travel from Square to Square .
Sample Input 1Copy
3 3 ... .#. ...
Sample Output 1Copy
10
There are ways to travel, as follows:
Sample Input 2Copy
4 4 ...# .... ..#. ....
Sample Output 2Copy
84
From , the queen can move to , , , , , or .
One possible path to is .
Sample Input 3Copy
8 10 .......... .......... .......... .......... .......... .......... .......... ..........
Sample Output 3Copy
13701937
Find the count modulo .