Problem:
We 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.

Incorrect submission (verdict: Wrong Answer):

import datetime
from decimal import Decimal, ROUND_DOWN
import heapq
from fractions import gcd
from functools import reduce
from collections import deque
# from math import factorial
import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import statistics
# import numpy as np
# n = int(input())
# n, m, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
#

# n = int(input())
h, w, k = list(map(int, input().split()))
# A = list(map(int, input().split()))
# a = list(map(int, input().split()))



# b = list(map(int, input().split()))


# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))

c = []
kuro = 0

col_sum = []
row_sum = []
for i in range(h):
    a = input()
    c.append(a)
    ac = a.count('#')
    kuro += ac
    col_sum.append(ac)

for i in range(w):
    cc = 0
    for j in range(h):
        if c[j][i] == "#":
            cc += 1
    row_sum.append(cc)

# print(col_sum)
# print(row_sum)
# print("----------")

if kuro == k:
    print(1)
    exit()

ans = 0

lll = row_sum+col_sum
for i in range(1, h+w):
    l = list(itertools.combinations(lll, i))
    # print(l)
    for j in range(len(l)):
        _max = max(l[j])
        if _max > k:
            m_count = 0
            tt = _max
            for k in range(i):
                if l[j][k] != _max or(l[j][k] == _max and m_count == 1):
                    tt -= l[j][k]
                elif l[j][k] == _max and m_count == 0:
                    m_count += 1
            if tt == k:
                ans += 1

        elif sum(l[j]) == k:
            ans += 1
# print(lll)
# print(ll)
print(ans)


Fixed, accepted submission:
h, w, f = list(map(int, input().split()))
c = [input() for i in range(h)]
count = 0
bit_h = []
for k in range(2**h):
    hh = []
    for l in range(h):
        if((k >> l) & 1):
            hh.append(1)
        else:
            hh.append(0)
    bit_h.append(hh)

bit_w = []
for i in range(2**w):
    ww = []
    for j in range(w):
        if((i >> j) & 1):
            ww.append(1)
        else:
            ww.append(0)
    bit_w.append(ww)

ans = 0
for i in range(len(bit_h)):
    for j in range(len(bit_w)):
        count = 0
        for k in range(h):
            for l in range(w):
                if bit_h[i][k] == 1 and bit_w[j][l] == 1 and c[k][l] == "#":
                    count += 1
        if count == f:
            ans += 1
print(ans)