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 related to rows.
An integer W (1 ≤ W ≤ 6), representing some quantity related to columns.
An integer K (1 ≤ K ≤ HW), representing some quantity.
A list of strings of length H, each containing W characters where 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.
```python
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
To generate test cases for the given problem statement, we need to consider generating random grids of varying sizes and contents within the provided constraints. Here's a Python function to generate such test cases:
```python
import random
def tcgen():
# Randomly choose H and W within the given constraints
H = random.randint(1, 6)
W = random.randint(1, 6)
# Randomly generate the grid
grid = []
for _ in range(H):
row = ''.join(random.choice(['.', '#']) for _ in range(W))
grid.append(row)
# Randomly choose K within the given constraints
K = random.randint(1, H * W)
# Output the test case
print(H, W, K)
for row in grid:
print(row)
# Example usage
for _ in range(5): # Generate 5 test cases
tcgen()
print() # Separate each test case output for readability
```
This function generates test cases with random values for \(H\), \(W\), and \(K\), and a grid of characters where each character is either `.` or `#`. The constraints are respected, and the grid is printed in the required format.
### Explanation:
- **H and W**: These are chosen randomly between 1 and 6, inclusive, to match the constraints.
- **Grid**: Each row of the grid is generated by randomly choosing characters from the set {'.', '#'}.
- **K**: This is chosen randomly within the range [1, H * W] to ensure it is within the valid range of possible black squares.
This generator can be used to produce various test cases to test the robustness of the solution to the problem.
Extract Arguments
def extract_arguments(fh):
H, W, K = map(int, fh.readline().strip().split())
grid = [fh.readline().strip() for _ in range(H)]
return H, W, K, grid