Orig Description
Score : 300 points
Problem StatementWe have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is ., and black if c_{i,j} is #.
Consider doing the following operation:
Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.
You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
Constraints
1 \leq H, W \leq 6
1 \leq K \leq HW
c_{i,j} is . or #.
InputInput is given from Standard Input in the following format:
H W K
c_{1,1}c_{1,2}...c_{1,W}
c_{2,1}c_{2,2}...c_{2,W}
:
c_{H,1}c_{H,2}...c_{H,W}
OutputPrint an integer representing the number of choices of rows and columns satisfying the condition.
Sample Input 12 3 2
..#
###
Sample Output 15
Five choices below satisfy the condition.
The 1-st row and 1-st column
The 1-st row and 2-nd column
The 1-st row and 3-rd column
The 1-st and 2-nd column
The 3-rd column
Sample Input 22 3 4
..#
###
Sample Output 21
One choice, which is choosing nothing, satisfies the condition.
Sample Input 32 2 3
##
##
Sample Output 30
Sample Input 46 6 8
..##..
.#..#.
#....#
######
#....#
#....#
Sample Output 4208
Extracted Specification
An integer H (1 ≤ H ≤ 6), representing some quantity or size.
An integer W (1 ≤ W ≤ 6), representing some quantity or size.
An integer K (1 ≤ K ≤ H*W), representing some quantity or size.
A list of H strings, each of length W, each character is either '.' or '#'.
### Example Input:
```
2
3
2
..#
###
```
### Function Signature:
Write a function f(H, W, K, grid) that takes in the input.
def f(H: int, W: int, K: int, grid: List[str]):
'''
H: an integer
W: an integer
K: an integer
grid: a list of strings
'''
Test Case Generator
Sure! Here's a Python function to generate test cases for the given problem statement. This function will create random grids and select random values for H, W, and K within the specified constraints.
```python
import random
def tcgen():
H = random.randint(1, 6)
W = random.randint(1, 6)
K = random.randint(1, H * W)
grid = []
for _ in range(H):
row = ''.join(random.choice(['.', '#']) for _ in range(W))
grid.append(row)
return H, W, K, grid
def format_tc(H, W, K, grid):
return f"{H} {W} {K}\n" + '\n'.join(grid)
# Example usage
H, W, K, grid = tcgen()
print(format_tc(H, W, K, grid))
```
This function `tcgen` generates random values for the grid dimensions \(H\) and \(W\), as well as the number \(K\) of black squares that should remain. It then constructs a grid of size \(H \times W\) with random '.' and '#' characters. The `format_tc` function formats the generated test case in the required input format for easy use.
Here is a quick example of what the output might look like when running the above code:
```
3 4 6
.#.#
#..#
##..
```
You can modify the `tcgen` function to customize the distribution of '.' and '#' if you want a specific kind of grid for testing purposes.
Extract Arguments
def extract_arguments(fh):
H, W, K = map(int, fh.readline().strip().split())
grid = []
for _ in range(H):
grid.append(fh.readline().strip())
return H, W, K, grid