A11107 | Guards In The Storehouse
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp owns a shop in the capital of Berland. Recently the criminal activity in the capital increased, so Polycarp is thinking about establishing some better security in the storehouse of his shop.
The storehouse can be represented as a matrix with $n$ rows and $m$ columns. Each element of the matrix is either . (an empty space) or x (a wall).
Polycarp wants to hire some guards (possibly zero) to watch for the storehouse. Each guard will be in some cell of matrix and will protect every cell to the right of his own cell and every cell to the bottom of his own cell, until the nearest wall. More formally, if the guard is standing in the cell $(x_{0},y_{0})$ , then he protects cell $(x_{1},y_{1})$ if all these conditions are met:
- $(x_{1},y_{1})$ is an empty cell;
- either $x_{0}=x_{1}$ and $y_{0}<=y_{1}$ , or $x_{0}<=x_{1}$ and $y_{0}=y_{1}$ ;
- there are no walls between cells $(x_{0},y_{0})$ and $(x_{1},y_{1})$ . There can be a guard between these cells, guards can look through each other.
Guards can be placed only in empty cells (and can protect only empty cells). The plan of placing the guards is some set of cells where guards will be placed (of course, two plans are different if there exists at least one cell that is included in the first plan, but not included in the second plan, or vice versa). Polycarp calls a plan suitable if there is not more than one empty cell that is not protected.
Polycarp wants to know the number of suitable plans. Since it can be very large, you have to output it modulo $10^{9}+7$ .
The storehouse can be represented as a matrix with $n$ rows and $m$ columns. Each element of the matrix is either . (an empty space) or x (a wall).
Polycarp wants to hire some guards (possibly zero) to watch for the storehouse. Each guard will be in some cell of matrix and will protect every cell to the right of his own cell and every cell to the bottom of his own cell, until the nearest wall. More formally, if the guard is standing in the cell $(x_{0},y_{0})$ , then he protects cell $(x_{1},y_{1})$ if all these conditions are met:
- $(x_{1},y_{1})$ is an empty cell;
- either $x_{0}=x_{1}$ and $y_{0}<=y_{1}$ , or $x_{0}<=x_{1}$ and $y_{0}=y_{1}$ ;
- there are no walls between cells $(x_{0},y_{0})$ and $(x_{1},y_{1})$ . There can be a guard between these cells, guards can look through each other.
Guards can be placed only in empty cells (and can protect only empty cells). The plan of placing the guards is some set of cells where guards will be placed (of course, two plans are different if there exists at least one cell that is included in the first plan, but not included in the second plan, or vice versa). Polycarp calls a plan suitable if there is not more than one empty cell that is not protected.
Polycarp wants to know the number of suitable plans. Since it can be very large, you have to output it modulo $10^{9}+7$ .
输入格式
The first line contains two numbers $n$ and $m$ — the length and the width of the storehouse ( $1<=n,m<=250$ , $1<=nm<=250$ ).
Then $n$ lines follow, $i$ th line contains a string consisting of $m$ characters — $i$ th row of the matrix representing the storehouse. Each character is either . or x.
Then $n$ lines follow, $i$ th line contains a string consisting of $m$ characters — $i$ th row of the matrix representing the storehouse. Each character is either . or x.
输出格式
Output the number of suitable plans modulo $10^{9}+7$ .
输入输出样例
输入 #1
1 3 .x.
输出 #1
3
输入 #2
2 2 xx xx
输出 #2
1
输入 #3
2 2 .. ..
输出 #3
10
输入 #4
3 1 x . x
输出 #4
2
In the first example you have to put at least one guard, so there are three possible arrangements: one guard in the cell $(1,1)$ , one guard in the cell $(1,3)$ , and two guards in both these cells.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted