Problem:
 Score : 300 points    Problem Statement 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.      Constraints  1 \leq H, W \leq 6  1 \leq K \leq HW  c_{i,j} is . or # .         Input Input 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}       Output Print an integer representing the number of choices of rows and columns satisfying the condition.        Sample Input 1 2 3 2
..#
###      Sample Output 1 5  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 2 2 3 4
..#
###      Sample Output 2 1  One choice, which is choosing nothing, satisfies the condition.       Sample Input 3 2 2 3
##
##      Sample Output 3 0       Sample Input 4 6 6 8
..##..
.#..#.
#....#
######
#....#
#....#      Sample Output 4 208

Solution (Python):
import sys

import math
import itertools
import random
H, W, K = map(int, input().split())
li = [[''] * W for i in range(H)]
for h in range(H):
    tmp=input()
    for w in range(W):
        li[h][w] = tmp[w]
tmpli = [0]*H
for h in range(H):
    tmpli[h] = h
tmpli2 = [0] * W
for w in range(W):
    tmpli2[w] = w
    ans = 0
for h in range(0,H+1):
    combi_H=list(itertools.combinations(tmpli, h))
    for w in range(0,W+1):
        combi_W = list(itertools.combinations(tmpli2, w))
        for x in combi_H:
            for y in combi_W:
                tx = list(x)
                ty = list(y)
                cnt=0
                for a in range(H):
                    if (a not in tx):
                        continue
                    for b in range(W):
                        if (b not in ty):
                            continue
                        if (li[a][b] == '
                            cnt += 1
                if (cnt == K):
                    ans += 1
print(ans)

Solution (Python):
import itertools
import copy
yoko,tate,left = map(int,input().split())
clist = []
ylist = [];tlist = []

for i in range(yoko+1):
    ylist += list(itertools.combinations(range(yoko),i))
for i in range(tate+1):
    tlist += list(itertools.combinations(range(tate),i))

for i in range(yoko):
    clist.append(list(input()))

counter = 0
def color(y,t,clist):
    global yoko,tate
    black = 0
    temp = copy.deepcopy(clist)
    if len(y) == 0:
        for tcomb in t:
            for j in range(yoko):
                temp[j][tcomb] = 'r'

    for ycomb in y:
        temp[ycomb][:] = ['r' for i in range(tate)]
        for tcomb in t:
            for j in range(yoko):
                    temp[j][tcomb] = 'r'

    for yokol in temp:

        black += yokol.count('
    if black == left:
        return True
    else:
        return False

for y in ylist:
    for t in tlist:
        if color(y,t,clist):
            counter += 1

print(counter)

Solution (Python):
H,W,K=map(int,input().split())
s=[]
for i in range(H):
    ss=str(input())
    s.append(ss)
ans=0

for i in range(2**H):
    seen=[]
    for n in range(H):
        if ((i>>n) & 1):
            seen.append(s[n])
    for j in range(2**W):
        count=0
        for m in range(W):
            if ((j>>m) & 1):
                for l in range(len(seen)):
                    if seen[l][m]=="
                        count+=1
        if count==K:
            ans+=1
print(ans)

Solution (Python):

import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

r,c,k = ip()
x = []
ct = 0
for i in range(r):
    s = list(input())
    x.append(s)
    ct += s.count('
ans = 0
for ii in range(2**r):
    for jj in range(2**c):
        a = bin(ii)[2:].zfill(r)
        b = bin(jj)[2:].zfill(c)
        
        new = 0
        for i in range(r):
            for j in range(c):
                if a[i] =='1' or b[j] == '1':
                    if x[i][j] == '
                        new += 1
        if ct-new == k:
            ans += 1
print(ans)

Solution (Python):
import numpy as np

h, w, k = map(int, input().split())
st = []
for _ in range(h):
    l = list(input())
    l = [l[i] for i in range(w)]
    st.append(l)
st = np.array(st)
st = np.where(st=='

cnt = 0
for i in range(2**w-1):
    tmp = [1] * w
    for j in range(w):
        if i >> j & 1:
            tmp[j] = 0
    for j in range(2**h-1):
        ker = np.array([tmp]*h)
        for x in range(h):
            if j >> x & 1:
                ker[x,:] = 0
        if np.sum(st * ker) == k:
            cnt+=1
print(cnt)

Solution (Python):
import itertools

H, W, K = [int(s) for s in input().split()]
MAP = [[s for s in input()] for _ in range(H)]

l_h = list(range(H))
l_w = list(range(W))


def count(h, w):
    cnt = 0
    for i in range(H):
        if i in h:
            continue
        for j in range(W):
            if j in w:
                continue
            if MAP[i][j] == '
                cnt += 1
    return cnt == K


c = 0

for ch in range(H+1):
    for hs in itertools.combinations(l_h, ch):
        for cw in range(W + 1):
            for ws in itertools.combinations(l_w, cw):
                c += count(list(hs), list(ws))


print(c)

Solution (Python):
H,W,K=map(int,input().split())
import numpy as np
def f(x):
  if x=='.':
    return 0
  else:
    return 1
C=np.array([list(map(f,list(input()))) for i in range(H)])
ans=0
for h in range(1,2**H):
  _h=[]
  for i in range(H):
    if h%2==1:
      _h.append(i)
    h=h//2
  
  for w in range(1,2**W):
    _w=[]
    for i in range(W):
      if w%2==1:
        _w.append(i)
      w=w//2
    _h=np.array(_h)
    _w=np.array(_w)
    a=C[_h[:,None],_w]
    if np.count_nonzero(a)==K:
      ans+=1
print(ans)

Solution (Python):
H,W,K = (int(i) for i in input().split())





master_list = []

for i in range(H):
  master_list.append(list(str(input())))

count = 0
for i in range(2**H):
  for j in range(2**W):
    K_count = 0
    bin_i = format(i,"b").zfill(H)
    bin_j = format(j,"b").zfill(W)
    for x in range(H):
      if bin_i[x] == "1":
        for y in range(W):
          if bin_j[y] =="1" and master_list[x][y] == "
            K_count += 1
    if K_count == K:
      count+=1

print(count)

Solution (Python):
H,W,K = map(int,input().split())
maze = [list(input()) for i in range(H)]

pattern = []
for i in range(2 ** (H+W)):
    tmp = [False] * (H+W)
    for j in range(H+W):
        if i >> j & 1:
            tmp[j] = True
    pattern.append(tmp)

import copy

ans = 0
for i in range(len(pattern)):
    copm = copy.deepcopy(maze)
    loop = 1
    for j in range(H+W):
        if loop <= H:
            loop += 1
            if pattern[i][j]:
                copm[j] = ['*' for i in range(W)]
        else:
            if pattern[i][j]:
                for k in range(len(maze)):
                    copm[k][j-H] = '*'
    k = 0
    for i in range(H):
        k += copm[i].count('
    if k == K:
        ans += 1

print(ans)

Solution (Python):
from itertools import combinations

def make_01(H, W, C):
    ban = [[0 for j in range(W)] for i in range(H)]
    for h in range(H):
        S = C[h]
        for w in range(W):
            if S[w] == '.':
                ban[h][w] = 0
            else:
                ban[h][w] = 1
    return ban

def countban(H, W, hc, wc, ban):
    
    
    for h in hc:
        for w in range(W):
            ban[h][w] = 0
    for w in wc:
        for h in range(H):
            ban[h][w] = 0
    
    val = sum(map(sum, ban))
    
    
    return val

def ban_copy(H, W, ban):
    bancopy = [[0 for j in range(W)] for i in range(H)]
    for h in range(H):
        for w in range(W):
            bancopy[h][w] = ban[h][w]
    return bancopy

def main():
    H, W, K = map(int, input().split())
    C = [input() for i in range(H)]
    ban = make_01(H, W, C)
    
    cnt = 0
    for n in range(H + 1):
        for hc in combinations(range(H), n):
            for m in range(W + 1):
                for wc in combinations(range(W), m):
                    tmpc = ban_copy(H, W, ban)
                    if K == countban(H, W, hc, wc, tmpc):
                        cnt += 1
    return cnt

if __name__ == '__main__':
    print(main())

Solution (Python):
H,W,K = map(int,input().split())

c = []
ch = [0]*H        
cw = [0]*W        
sum_cnt = 0         
for i in range(H):
    c_buf = input()
    ch[i] = c_buf.count('
    for j in range(W):
        if c_buf[j] == '
            cw[j] += 1
    sum_cnt += ch[i]
    c.append(c_buf)

import copy
cw_buf = copy.copy(cw)
ans = 0

for i in range(2**H):
    cw = copy.copy(cw_buf)
    cnt = sum_cnt
    for i2 in range(H):
        if (i >> i2) & 1:
            cnt -= ch[i2]
            for j in range(W):
                if c[i2][j] == '
                    cw[j] -= 1

    for j in range(2**W):
        cnt2 = cnt
        for j2 in range(W):
            if (j >> j2)&1:
                cnt2 -= cw[j2]

        if cnt2 == K:
            ans += 1

print(ans)

Solution (Python):
import copy
h, w, k = map(int, input().split())
chiz_m = [[] for _ in range(w)]
for _ in range(h):
    tmp_list = input()
    for i in range(w):
        chiz_m[i].append(tmp_list[i])
chiz = copy.deepcopy(chiz_m)
n=12
perms=[]
for i in range(2**n):
    list2 = []
    for j in range(n):
        if (i >> j) &1 == 1:
            list2.append(1)
        else:
            list2.append(0)
    perms.append(list2)

def draw(rc):
    if rc < 6:
        for i in range(w):
            chiz[i][rc] = '='
    else:
        for i in range(h):
            chiz[rc-6][i] = '='
res = 0
for perm in perms:
    for idx,x in enumerate(reversed(perm[:6])):
        if x == 1:
            break
    if 6-idx > h:
        continue
    for idx,x in enumerate(reversed(perm[-6:])):
        if x == 1:
            break
    if 6-idx > w:
        continue
    for b in range(12):
        if b < 6:
            if b < h:
                if perm[b] == 1:
                    draw(b)
            else:
                continue
        else:
            if b-6 < w:
                if perm[b] == 1:
                    draw(b)
            else:
                continue
    cnt = 0
    for i in range(w):
        for j in range(h):
            if chiz[i][j] == "
                cnt += 1
    
    
    if cnt == k:
        res += 1
    chiz = copy.deepcopy(chiz_m)
print(res)

Solution (Python):

import copy
import numpy as np
from itertools import combinations


def main():
    H, W, K = map(int, input().split())
    c = np.array([list(input()) for _ in range(H)], dtype='str')
    cnt = 0

    h_pattern = []
    w_pattern = []

    for h_num in range(H + 1):
        h_pattern.extend(list(combinations(range(H), h_num)))

    for w_num in range(W + 1):
        w_pattern.extend(list(combinations(range(W), w_num)))

    cnt = 0
    for hp1 in h_pattern:
        for wp1 in w_pattern:
            d = copy.deepcopy(c)
            for hp2 in hp1:
                d[hp2, :] = 'x'
            for wp2 in wp1:
                d[:, wp2] = 'x'
            if np.count_nonzero(d == '
                cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):
from itertools import combinations

h, w, k = map(int, input().split())

c = [list(input()) for i in range(h)]

def make(a):
    new = []
    for i in a:
        new.append(c[i])
    return new

def counter(lines, b):
    cnt = 0

    for i in b:
        for j in lines:
            if j[i] == '
                cnt += 1
    if cnt == k:
        return 1
    else:
        return 0
            


count = 0
for r in range(1,h+1):
    for i in combinations(range(h), r):
        new = make(i)
        for l in range(1, w+1):
            for j in combinations(range(w), l):
                num =counter(new, j)
                count += num
print(count)

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter



import bisect
h,w,k=map(int,input().split())
c=[input() for _ in range(h)]
ans=0
n=2**h
m=2**w
for x in range(n):
    for y in range(m):
        count=0
        for i in range(h):
            for j in range(w):
                if (x>>i)&1 and (y>>j)&1 and c[i][j]=="
                    count+=1
        if count==k:
            ans+=1
print(ans)

Solution (Python):
from copy import deepcopy
from itertools import combinations, product

H, W, K = map(int, input().split())
board = []
for _ in range(H):
    row = input()
    row = [r == "
    board.append(row)

all_h_comb = [()]
for r in range(1, H):
    comb_obj = combinations(range(H), r)
    all_h_comb += list(comb_obj)
all_w_comb = [()]
for c in range(1, W):
    comb_obj = combinations(range(W), c)
    all_w_comb += list(comb_obj)
all_comb = list(product(all_h_comb, all_w_comb))

res = 0
for comb in all_comb:
    r, c = comb
    tmp_board = deepcopy(board)
    for _r in r:
        tmp_board[_r] = [False] * W
    for _c in c:
        for b in tmp_board:
            b[_c] = False
    s = sum(sum(l) for l in tmp_board)
    if s == K:
        res += 1
print(res)

Solution (Python):
h,w,v = map(int,input().split())
c = []
for i in range(h):
    c.append(input())
b = 0
x = []
for i in range(h):
    x.append([0]*w)
    for j in range(w):
        if(c[i][j] == '
            b += 1

p = 0
for i in range(2**h):
    for j in range(2**w):
        x = bin(64^i)
        y = bin(64^j)
        cnt = 0
        for k in range(1,h+1):
            for l in range(1,w+1):
                if(x[-k] == '1' and y[-l] == '1' and c[k-1][l-1] == '
                    cnt += 1
        if(cnt == v):
            p += 1
print(p)

Solution (Python):



import numpy as np


def fill_red(height, width, table, h, w):
    for hn in range(h):
        if (2 ** hn) & height == (2 ** hn):
            table[hn:hn + 1] = '+'

    for wn in range(w):
        if (2 ** wn) & width == (2 ** wn):
            table[:, wn:wn+1] = '+'

    return table


def count_black(table, k):
    if np.sum(table == "
        return True
    else:
        return False


def main():
    h, w, k = map(int, input().split())
    original_table = []

    while True:
        try:
            row = list(input())
            original_table.append(row)
        except EOFError:
            break

    original_table = np.array(original_table)

    counter = 0
    for height in range(2**h):
        for width in range(2**w):
            table = original_table.copy()
            table = fill_red(height, width, table, h, w)
            if count_black(table, k):
                counter += 1

    print(counter)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations
import copy

h, w, k = map(int, input().split())
_h = [i for i in range(h)]
_w = [i for i in range(w)]

h_comb = []
w_comb = []
for i, _ in enumerate(_h, 1):
    for j in combinations(_h, r=i):
        h_comb.append(list(j))
h_comb.append([])

for i, _ in enumerate(_w, 1):
    for j in combinations(_w, r=i):
        w_comb.append(list(j))
w_comb.append([])

field = []
for i in range(h):
    field.append(list(input()))

ans = 0
for hc in h_comb:
    for wc in w_comb:
        tmp = copy.deepcopy(field)

        for i in hc:
            for j in range(w):
                tmp[i][j] = '.'
        for j in wc:
            for i in range(h):
                tmp[i][j] = '.'
        count = 0
        for i in range(h):
            for j in range(w):
                if tmp[i][j] == '
                    count += 1
        if count == k:
            ans += 1

print(ans)

Solution (Python):
def resolve():
    h,w,K = map(int, input().split())
    mas = [list(input()) for i in range(h)]
    wk = []
    hk = []
    for i in range(h):
        plus = 0
        for j in range(w):
            if mas[i][j] == "
                plus += 1
        hk.append(plus)
    for i in range(w):
        plus = 0
        for j in range(h):
            if mas[j][i] == "
                plus += 1
        wk.append(plus)
    total = sum(wk)

    ans = 0
    for i in range(2**h):
        vert = []
        for k in range(h):
            vert.append((i>>k)&1)
        for j in range(2**w):
            hor = []
            for m in range(w):
                hor.append((j>>m)&1)
            subt = 0

            for n in range(len(vert)):
                subt += vert[n] * hk[n]
            for n in range(len(hor)):
                subt += hor[n] * wk[n]
            for n in range(len(vert)):
                for o in range(len(hor)):
                    if (vert[n] == 1) and (hor[o] == 1) and (mas[n][o] == "
                        subt -= 1

            if total-subt == K:
                ans += 1


    print(ans)
resolve()

Solution (Python):
import copy
hwk = input('')
h = int(hwk.split(' ')[0])
w = int(hwk.split(' ')[1])
k = int(hwk.split(' ')[2])

clist = []
for i in range(h):
    clist.append(input())

cnt_all=0
for i in range(2**(h+w)):
    bag=[]
    clist2 = []
    for line in clist:
        clist2.append(line)
    for j in range(h+w):
        if ((i>>j)&1):
            if j < h:                
                
                bag.append("Y:{}".format(j))
                clist2[j] = 'R'*w
            else:
                
                bag.append("X:{}".format(j-h))
                for i2 in range(h):
                    line = list(clist2[i2])
                    line[j-h] ='R'
                    clist2[i2] = "".join(line)
    cnt = 0
    for c in clist2:
        cnt+=c.count('
    if cnt==k:

        cnt_all+=1

print(cnt_all)

Solution (Python):
from collections import deque

H, W, K = map(int, input().split())
c = []
for i in range(H):
    c.append(input())

def check(r):
    counter = 0
    for h in range(H):
        for w in range(W):
            if c[h][w] == '.':
                continue
            else:
                
                if r[h] or r[H + w]:
                    continue
                else:
                    counter += 1  
    return 1 if counter == K else 0

depth = 0
queue = deque()
queue.append(([], 0))
answer = 0
while len(queue) != 0:
    r, depth = queue.pop()
    if depth == H + W:
        answer += check(r)
    else:
        for mask in [True, False]:
            queue.append((r + [mask], depth + 1))
print(answer)

Solution (Python):
import copy
def main():
    H,W,K = map(int, input().split())
    road = [[0]*W for _ in range(H)]
    for i in range(H):
        c = input()
        for j in range(W):
            if c[j]=='.':
                road[i][j] = 0
            else:
                road[i][j] = 1
    ans = 0
    for h in range(2**H):
        for w in range(2**W):
            harr = [0]*H
            warr = [0]*W
            for i in range(H):
                harr[H-i-1] = (h>>i)&1
            for i in range(W):
                warr[W-i-1] = (w>>i)&1
            tmp = 0
            for i in range(H):
                for j in range(W):
                    if harr[i]==0 and warr[j]==0 and road[i][j]==1:
                        tmp += 1
            if tmp==K: ans += 1
    print(ans)

main()

Solution (Python):
from itertools import combinations as co
h,w,k=map(int,input().split())
m=[list(input()) for i in range(h)]
pr=[]
pc=[]
for i in range(h+1):
  pr+=list(co(range(h),i))
for i in range(w+1):
  pc+=list(co(range(w),i))
a=0
for i in pr:
  for j in pc:
    n=[m[x][:] for x in range(h)]
    for x in i:
      for y in range(w):
        n[x][y]="."
    for x in j:
      for y in range(h):
        n[y][x]="."
    if sum(x.count("
      a+=1
print(a)

Solution (Python):
from itertools import product
from copy import deepcopy
H, W, K = map(int, input().split())
c = []
for _ in range(H):
    c.append(list(input()))
ans = 0
for h in range(2**H):
    for w in range(2**W):
        tmp = deepcopy(c)
        for i in range(H):
            for j in range(W):
                if 1&(w>>j) or 1&(h>>i):
                    tmp[i][j] = "?"
        cnt = 0
        for i in range(H):
            cnt += tmp[i].count("
        if cnt==K:
            ans += 1
print(ans)

Solution (Python):
import sys
import itertools
import copy
H,W,K=map(int, sys.stdin.readline().split())
S=[ sys.stdin.readline().strip() for _ in range(H) ]

h_cnt=[]
for s in S:
    cnt=0
    for x in s:
        if x=="
            cnt+=1
    h_cnt.append(cnt)

T=sum(h_cnt)

w_cnt=[]
w=0
for w in range(W):
    cnt=0
    for h in range(H):
        if S[h][w]=="
            cnt+=1
    w_cnt.append(cnt)

HL=list( itertools.product(range(2), repeat=H) )
WL=list( itertools.product(range(2), repeat=W) )

ans=0
for hl in HL:
    for wl in WL:
        total=copy.deepcopy(T)
        for i,h in enumerate(hl):
            if h==1:
                total-=h_cnt[i]
        for j,w in enumerate(wl):
            if w==1:
                total-=w_cnt[j]

        for i,h in enumerate(hl):
            for j,w in enumerate(wl):
                if h&w==1:
                    if S[i][j]=="
                        total+=1

        if total==K:
            ans+=1
print ans

Solution (Python):
import itertools
import copy
H,W,K = (int(i) for i in input().split())

a = [[0 for j in range(6)] for i in range(6)]

for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == ".":
            a[i][j] = 0
        else:
            a[i][j] = 1

result = 0
for row in a:
    result += sum(row)

HH = range(H)
WW = range(W)

resH = [()]
resW = [()]
for n in range(1,len(HH)+1):
    for conb in itertools.combinations(HH, n):
        resH.append(list(conb)) 
for n in range(1,len(WW)+1):
    for conb in itertools.combinations(WW, n):
        resW.append(list(conb)) 

ko = 0
for i in resH:
    for j in resW:
        b = copy.deepcopy(a)
        p = itertools.product(i, j)
        for ii in i:
            for jj in range(W):
                b[ii][jj] = 0
        for jj in j:
            for ii in range(H):
                b[ii][jj] = 0

        result = 0
        for row in b:
            result += sum(row)
        if result == K:
            ko += 1

print(ko)

Solution (Python):
hwk,*ccc = open(0).read().splitlines()

H,W,K = map(int, hwk.split())

ccc = list(map(list, ccc))

from itertools import product

from copy import deepcopy

ans = 0

count = 0

for hs in product([0,1], repeat=H):
    for ws in product([0,1], repeat=W):
        tmp = deepcopy(ccc)
        for h,b in enumerate(hs):
            if b:
                tmp[h] = list('r'* W)
        for h in range(H):
            for w,c in enumerate(ws):
                if c:


                    tmp[h][w] = 'r'



        ans += (''.join(sum(tmp, [])).count('



print(ans)

Solution (Python):
import itertools

inp = input()
split = inp.split()
h = int(split[0])
w = int(split[1])
k = int(split[2])
lines=[]
result = 0
for i in range(h):
    lines.append(input())
hList = list(range(h+1))[1:]
wList = list(range(w+1))[1:]
hResult = [[]]
wResult = [[]]
for n in range(1,len(hList)+1):
    for conb in itertools.combinations(hList, n):
        hResult.append(list(conb)) 
for n in range(1,len(wList)+1):
    for conb in itertools.combinations(wList, n):
        wResult.append(list(conb)) 
def check(hBanish, wBanish):
    result = 0
    for hNum in range(1, h + 1):
        if hNum in hBanish:
            continue
        else:
            for wNum in range(1, w + 1):
                if wNum in wBanish:
                    result += 0
                elif lines[hNum-1][wNum-1] == "
                    result += 1
                else:
                    result += 0
    return result

for hBanish in hResult:
    for wBanish in wResult:
        if check(hBanish, wBanish) == k:
            result  += 1
print(result)

Solution (Python):
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]

ans = 0
for i in range(2**(H+W)):
  height = [x for x in range(H)]
  width = [y for y in range(W)]
  for j in range(H):
    if i >> j & 1:
      height.remove(j)
  for k in range(H, H+W):
    if i >> k & 1:
      width.remove(k-H)
  num = 0
  for p in height:
    for q in width:
      if c[p][q] == "
        num += 1
  if num == K:
    ans += 1
print(ans)

Solution (Python):
import itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

h, w, k = map(int, readline().split())
g = [list(readline().decode().rstrip()) for _ in range(h)]

ans = 0
for i in itertools.product([0, 1], repeat=h):
    for j in itertools.product([0, 1], repeat=w):
        cnt = 0
        for n,a in enumerate(i):
            for m, b in enumerate(j):
                if a == 1 and b == 1 and g[n][m] == '
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Solution (Python):
h, w, k = map(int, input().split())

p = [input() for i in range(h)]
H =[0]*h
W = [0]*w

b = 0
for i in range(h):
  for j in range(w):
    if p[i][j] == '
      H[i] += 1
      W[j] += 1
      b += 1
   
d = b - k

ans = 0

for i in range(2**h):
  for k in range(2**w):
    black1 = 0
    for j in range(h):

      if ((i>>j)&1):
        black1 += H[j]
    
    for l in range(w):

      if ((k>>l)&1):
        black1 += W[l]
        
    for j in range(h):
      for l in range(w):
        if (i>>j)&1 and (k>>l)&1 and p[j][l] == '
          black1 -= 1

    
    if black1 == d:
      ans += 1

print(ans)

Solution (Python):
import sys
import copy
h,w,k = map(int, sys.stdin.readline().rstrip("\n").split())
labyrinth = []
for _ in range(h): 
    l = list(sys.stdin.readline().rstrip("\n"))
    labyrinth.append(l)
l_h = [format(i, 'b').zfill(h) for i in range(2**h)]
l_w = [format(i, 'b').zfill(w) for i in range(2**w)]
ans = 0
for hi in l_h:
    for wi in l_w:
        labyrinth_new = copy.deepcopy(labyrinth)
        s = 0
        for hii in range(h):
            if hi[hii] == '1':
                labyrinth_new[hii] = ['r']*w
        for wii in range(w):
            if wi[wii] == '1':
                for _ in range(h):
                    labyrinth_new[_][wii] = 'r'
        for _ in range(h):
            s += labyrinth_new[_].count('
        if s == k:
            ans += 1
print(ans)

Solution (Python):
h, w, k = map(int, input().split())
grid = [None]*h
for i in range(h):
  grid[i] = input()

ans = 0
for i in range(2**h):
  key = [0]*h
  for a in range(h):
    if (i>>a)&1:
      key[a] = 1
  for j in range(2**w):
    key2 = [0]*w
    for b in range(w):
      if (j>>b)&1:
        key2[b] = 1
    count = 0
    for p in range(h):
      for q in range(w):
        if grid[p][q] == "
          count += 1
    if count == k:
      ans += 1
print(ans)

Solution (Python):
h,w,k = map(int, input().split())
import sys
c = [[str(a) for a in l.strip()] for l in sys.stdin]

ans = 0

b = 2 ** (h + w)
for i in range(b):
  for j in range(h):
    for q in range(w):
      if ((i >> j) & 1) and (i >> (q+h)) & 1:
        if c[j][q] == "
          sum += 1
  if sum == k:
    ans += 1
  sum = 0
    
print(ans)

Solution (Python):
import itertools
import numpy as np

h, w, k = map(int, input().split())
ans = 0
grid = [[m for m in input()] for _ in range(h)]

flg=[True, False]
for fh in itertools.product(flg, repeat=h):
    for fw in itertools.product(flg, repeat=w):
        cnt = 0
        cflg = True
        for i in range(h):
            if not fh[i]: continue
            if not cflg: break
            for j in range(w):
                if not fw[j]: continue
                if grid[i][j] == '
                if cnt > k:
                    cflg = False 
                    break
                    
        if cnt == k: ans += 1
print(ans)

Solution (Python):


import sys
import math
import time

import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools









H,W,K = map(int, input().split())
G = []
tate = [0]*W
yoko = [0]*H
for i in range(H):
  G.append(list(input()))

for i in range(W):
  for j in range(H):
    if(G[j][i]=="
      tate[i]+=1
      yoko[j]+=1

su = sum(tate)
ans = su
ans2 = 0


for i in range(2**W):
  for j in range(2**H):
    temp = copy.deepcopy(G)
    for k in range(W):
      if((i>>k) & 1):
        for l in range(H):
          if(temp[l][k]=="
            temp[l][k]="."
            ans-=1
    for m in range(H):
      if((j>>m) & 1):
        for o in range(W):
          if(temp[m][o]=="
            temp[m][o]="."
            ans-=1
    if(ans==K):
      ans2 += 1
    ans = su
    



print(ans2)

Solution (Python):
import copy

h,w,k=[int(aaa) for aaa in input().split()]

c=[]
ans=0

for _ in range(h):
    c.append(list(input()))

for i in range(2**h):
    for j in range(2**w):
        d=copy.deepcopy(c)
        i2='000000'+format(i,'b')
        j2='000000'+format(j,'b')
        
        
        for k2 in range(1,h+1):
            if i2[-k2]=='1':
                for i3 in range(w):
                    d[k2-1][i3]='@'
        for l in range(1,w+1):
            if j2[-l]=='1':
                for j3 in range(h):
                    d[j3][l-1]='@'

        
        cnt=0
        for d2 in d:
            cnt+=d2.count('
        
        if cnt==k:
            ans+=1
print(ans)

Solution (Python):
h, w, k = map(int, input().split())

X = [input() for _ in range(h)]

Y = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    for j in range(w):
        if X[i][j] == '
            Y[i][j] = 1


ans=0
for j in range(2**h):
    H=[]
    for _h in range(h):
        if (j>>_h)&1:
            H.append(Y[_h])
    
    for l in range(2**w):
        _ans = 0
        for _w in range(w):
            if (l>>_w)&1:
                _ans += sum([_H[_w] for _H in H])
        if _ans == k:
            ans += 1

print(ans)

Solution (Python):
import itertools
h,w,f=map(int, input().split())
box=[]
cnt=0
for i in range(h):
  box.append(list(str(input())))
htarget=list(itertools.product([0,1], repeat=h))
wtarget=list(itertools.product([0,1], repeat=w))
for j in range(len(htarget)):
  boxtemp=[["0"] * w for i in range(h)]
  for k in range(len(wtarget)):
    cnttemp=0
    for p in range(h):
      for q in range(w):
        if htarget[j][p]==1 or wtarget[k][q]==1:
          boxtemp[p][q]="?"
        else:
          boxtemp[p][q]=box[p][q]
    for s in range(h):
      for t in range(w):
        if boxtemp[s][t]=="
          cnttemp+=1
    if cnttemp==f:
      cnt+=1
print(cnt)