A1016 | Balanced Subsets--Platinum
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Farmer John's pasture can be regarded as a large 2D grid of square "cells"
(picture a huge chessboard) labeled by the ordered pairs $(i,j)$ for each
$1\le i\le N$, $1\le j\le N$ ($1\le N\le 150$). Some of the cells contain
grass.
A nonempty subset of grid cells is called "balanced" if the following
conditions hold:
1. All cells in the subset contain grass.
2. The subset is 4-connected. In other words, there exists a path from any cell in the subset to any other cell in the subset such that every two consecutive cells of the path are horizontally or vertically adjacent.
3. If cells $(x_1,y)$ and $(x_2,y)$ ($x_1\le x_2$) are part of the subset, then all cells $(x,y)$ with $x_1\le x\le x_2$ are also part of the subset.
4. If cells $(x,y_1)$ and $(x,y_2)$ ($y_1\le y_2$) are part of the subset, then all cells $(x,y)$ with $y_1\le y\le y_2$ are also part of the subset.
Count the number of balanced subsets modulo $10^9+7$.
(picture a huge chessboard) labeled by the ordered pairs $(i,j)$ for each
$1\le i\le N$, $1\le j\le N$ ($1\le N\le 150$). Some of the cells contain
grass.
A nonempty subset of grid cells is called "balanced" if the following
conditions hold:
1. All cells in the subset contain grass.
2. The subset is 4-connected. In other words, there exists a path from any cell in the subset to any other cell in the subset such that every two consecutive cells of the path are horizontally or vertically adjacent.
3. If cells $(x_1,y)$ and $(x_2,y)$ ($x_1\le x_2$) are part of the subset, then all cells $(x,y)$ with $x_1\le x\le x_2$ are also part of the subset.
4. If cells $(x,y_1)$ and $(x,y_2)$ ($y_1\le y_2$) are part of the subset, then all cells $(x,y)$ with $y_1\le y\le y_2$ are also part of the subset.
Count the number of balanced subsets modulo $10^9+7$.
输入格式
The first line contains $N$.
The next $N$ lines each contain a string of $N$ characters. The $j$-th
character of the $i$-th line from the top is equal to G if the cell at $(i,j)$
contains grass, or . otherwise.
The next $N$ lines each contain a string of $N$ characters. The $j$-th
character of the $i$-th line from the top is equal to G if the cell at $(i,j)$
contains grass, or . otherwise.
输出格式
The number of balanced subsets modulo $10^9+7$.
输入输出样例
输入 #1
2 GG GG
输出 #1
13
For this test case, all 4-connected subsets are balanced.
G. .G .. .. GG .G .. G. GG .G G. GG GG
.., .., G., .G, .., .G, GG, G., G., GG, GG, .G, GG
G. .G .. .. GG .G .. G. GG .G G. GG GG
.., .., G., .G, .., .G, GG, G., G., GG, GG, .G, GG
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted