Code lock
Time limit2sMemory limit1024 MB
Count the connected sets of exactly k button cells on a grid of up to 30 by 30 cells, where cells sharing a side connect.
- Level
Medium7 of 10
- Topics
- Bit manipulation, BFS, Brute force
- Solved
- No attempts yet
Problem
A company named <<Замки и замки>> recently developed a new type of code lock for installing on gates. The lock panel is a rectangle cells wide and cells high. Some cells have buttons.
A code is entered by pressing buttons at the same time. To make the code easier to remember, the buttons used in it must form a connected region. A region is connected if you can get from any cell of the region to any other cell by moving only between cells of the region that share a side. An important measure of the lock's reliability is the number of different codes that can be entered on it.
Write a program that computes this number.
Input
The first line contains three integers , , and (; ). Each of the next lines contains characters. The character # marks a button, and . marks an empty cell.
Output
Print one integer: the number of codes that satisfy the requirements.
Hint
The figure shows one possible code for the second input.
