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



Sample input:
2 3 2
..#
###


Sample output:
5

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
c = [list(input()) for i in range(h)]
ans = 0
for hh in range(2**h):
    for ww in range(2**w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if (hh >> i) & 1 and (ww >> j) & 1:
                    if c[i][j] == '#':
                        cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
h, w, K = map(int, input().split())

C = []

ans = 0

for i in range(h):
  c = input()
  C.append(c)
  
for i in range(2 ** h):
  for k in range(2 ** w):
    black = 0
    for j in range(h):
      for l in range(w):
        if ((i >> j) & 1) == 0 and ((k >> l) & 1) == 0 and C[j][l] == '#':
          black += 1
    if black == K:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools
H,W,K = map(int, input().split())

matrix =[]
rowblack = []

for i in range(H):
    row = list(input())
    matrix.append(row)
    rowblack.append(row.count('#'))

allblacks = sum(rowblack)
ans = 0

selectRows = list(itertools.product([0,1], repeat=H))
selectColumns = list(itertools.product([0,1], repeat=W))

for selectRow in selectRows:
    for selectColumn in selectColumns:
        counter = 0

        for row in range(H):
            for column in range(W):
                if selectRow[row] == 0 and selectColumn[column] == 0 and matrix[row][column] == '#':
                    counter += 1
        
        if counter == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from itertools import product

H,W,K=map(int,input().split())
C=[input() for _ in range(H)]
#print(C)

ans=0
for i in product([0,1],repeat=H):
    for j in product([0,1],repeat=W):
        cnt=0
        for row in range(H):
            for col in range(W):
                if (C[row][col]=="#" and i[row]==0 and j[col]==0):
                    cnt+=1
        if cnt==K:
            ans+=1
                    
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
H,W,K=map(int,input().split())

A = [input() for j in range(H)]
    
ans=0

for i in product([0,1],repeat=H):
    for j in product([0,1],repeat=W):
        cnt=0
        for row in range(H):
            for col in range(W):
                if (A[row][col]=="#" and i[row]==0 and j[col]==0):
                    cnt+=1
        if cnt==K:
            ans+=1
        
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
H,W,K=map(int,input().split())

A = [input() for j in range(H)]

ans=0
for i in product([1,0],repeat=H):
    for j in product([1,0],repeat=W):
        cnt=0
        for row in range(H):
            for col in range(W):
                if ((A[row][col]=="#") and ((i[row]==0) and j[col]==0)):
                    cnt+=1
        if cnt==K:
            ans+=1
            
print(ans)

Submission status: Accepted

Solution code:
h, w, k = [int(i) for i in input().split()]
a = [input() for j in range(h)]

ans = 0
for mi in range(1 << h):
    for mj in range(1 << w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if ((mi >> i) & 1) and ((mj >> j) & 1) and a[i][j] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
h, w, k = [int(i) for i in input().split()]
a = [input() for j in range(h)]

ans = 0
for mi in range(1 << h):
    for mj in range(1 << w):
        bi = [i for i in range(h) if ((mi >> i) & 1) == 0]
        bj = [j for j in range(w) if ((mj >> j) & 1) == 0]
        cnt = 0
        for i in range(h):
            if i in bi:
                continue
            for j in range(w):
                if j in bj:
                    continue
                if a[i][j] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
c = [list(input()) for i in range(h)]
ans = 0
for hh in range(2**h):
    for ww in range(2**w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if (hh >> i) & 1 and (ww >> j) & 1:
                    if c[i][j] == '#':
                        cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
nums=input().rstrip().split()
num=[]
for i in range(len(nums)):
    num.append(int(nums[i]))
main=[]
for i in range(num[0]):
    main.append(input().rstrip())
result=0
for h in range(2**num[0]):
    h_str=format(h,'0'+str(num[0])+'b')
    for w in range(2**num[1]):
        w_str=format(w,'0'+str(num[1])+'b')
        count=0
        for i in range(num[0]):
            for j in range(num[1]):
                if main[i][j]=='#' and h_str[i]!='1' and w_str[j]!='1':
                    count+=1
        if count==num[2]:
            result+=1
print(result)

Submission status: Accepted

Solution code:
from itertools import product

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

c_map = [list(input()) for _ in range(h)]

ans = 0

for row_bit in list(product([0,1],repeat=h)):
    for col_bit in list(product([0,1],repeat=w)):
        cnt = 0
        for i in range(h):
            for j in range(w):
                # row_bit,col_bitがともに「1」のとき塗りつぶされてないとする
                if c_map[i][j] == "#" and (row_bit[i] and col_bit[j]):
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
#print(c)
ans = 0
from itertools import product

for rb in product(range(2), repeat=h):
    for cb in product(range(2), repeat=w):
        cnt = 0
        for row in range(h):
            for col in range(w):
                if c[row][col] == "#" and rb[row]==0 and cb[col]==0:
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
h,w,k = map(int , input().split())
c=[]
for i in range(h):
    cc = input()
    c.append(cc)
ans = 0
for i in range(1 << h):
    for j in range( 1 << w):
        cnt = 0
        for kk in range(h):
            for l in range(w):
                if (c[kk][l] == '#' and (not (i & (1 << kk))) and (not (j & (1 << l)))):
                    cnt += 1
        if (cnt == k): ans += 1

print(ans)

Submission status: Accepted

Solution code:
number=list(map(int,input().split()))
H,W,K=number[0],number[1],number[2]
answer=0
nums=[]
for i in range(H):
    tmp=list(str(input()))
    nums.append(tmp)
count=0
for cowmask in range(1<<H):
    for rowmask in range(1<<W):
        count=0
        for x in range(H):
            for y in range(W):
                if (cowmask>>x)&1==0 and (rowmask>>y)&1==0 and nums[x][y]=="#":
                    count+=1
        if count==K:
            answer+=1
            
print(answer)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
c=[list(input()) for _ in range(h)]
ans=0
for i in range(2**h):
    for j in range(2**w):
        black=0
        for m in range(h):
            for n in range(w):
                if (i>>m)&1==0 and (j>>n)&1==0 and c[m][n]=='#':
                    black+=1
        if black==k:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
h,w,k = map(int,input().split())
c = [list(input()) for _ in range(h)]
cnt = 0
for c_h in range(2**h):
    for c_w in range(2**w):
        black = 0 
        for i in range(h):
            for j in range(w):
                if (c_h >> i)&1==0 and (c_w >> j)&1==0:
                    if c[i][j]=='#':
                        black += 1
        if black == k:
            cnt += 1
print(cnt)

Submission status: Accepted

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

M = [input() for i in range(H)]

# O(36)
def count(rows, columns):

  M2 = [[M[i][j] for j in range(W)] for i in range(H)]

  for i in range(H):
    if ((1 << i) & rows):
      for j in range(W):
        M2[i][j] = 'r'
  
  for i in range(W):
    if ((1 << i) & columns):
      for j in range(H):
        M2[j][i] = 'r'

  c = 0
  for i in range(H):
    for j in range(W):
      if M2[i][j] == '#':
        c += 1
  return c

res = 0
for i in range(1 << H):
  for j in range(1 << W):
    if (count(i, j) == K):
      res += 1

print(res)

Submission status: Accepted

Solution code:
import copy
import itertools
h, w, k = map(int,input().split())
masu = []
for _ in range(h):
    masu.append(list(input()))

cnt = 0
for i in range(2**h):
    for j in range(2**w):
        masu_copy = copy.deepcopy(masu)

        for ii in range(h):
            if 1 & (i >> ii):
                for y in range(w):
                    masu_copy[ii][y] = '.'

        for jj in range(w):
            if 1 & (j >> jj):
                for x in range(h):
                    masu_copy[x][jj] = '.'
        tmp_masu = list(itertools.chain.from_iterable(masu_copy))
        if tmp_masu.count('#') == k:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
H, W, K = list(map(int, input().split()))
s = []
for i in range(H):
    row = input()
    s.append(row)

ans = 0
for i in range(1 << H):
    for j in range(1 << W):
        cnt = 0
        for hi in range(H):
            for wi in range(W):
                if i >> hi & 1:
                    continue
                if j >> wi & 1:
                    continue
                if s[hi][wi] == '#':
                    cnt += 1
        if cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
h,w,k=map(int, input().split())
board = [list(input()) for _ in range(h)]
ans=0
for paint_h in range(2**h):
  for paint_w in range(2**w):
    cnt=0
    for i in range(h):
      for j in range(w):
        if (paint_h>>i)&1==0 and (paint_w>>j)&1==0:
          if board[i][j]=='#':
            cnt+=1
    if cnt==k:
      ans += 1
print(ans)

Submission status: Accepted

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

a1 = []
a2 = []


def f():
    pass


at1 = [None] * H


def dfs1(pos: int):
    if pos == H:
        # print(a)
        a1.append(at1.copy())
        return

    at1[pos] = 0
    dfs1(pos + 1)

    at1[pos] = 1
    dfs1(pos + 1)


at2 = [None] * W


def dfs2(pos: int):
    if pos == W:
        # print(a)
        a2.append(at2.copy())
        return

    at2[pos] = 0
    dfs2(pos + 1)

    at2[pos] = 1
    dfs2(pos + 1)


dfs1(0)
dfs2(0)

# print(a1)
# print(a2)

ans = 0

for ai in a1:
    for aj in a2:
        g = []
        for i in range(H):
            arr = [None] * W
            g.append(arr)

        for i, aii in enumerate(ai):
            if aii == 1:
                g[i] = ['r'] * W

        for i, aji in enumerate(aj):
            if aji == 1:
                for j in range(H):
                    g[j][i] = 'r'

        # print(ai, aj, g)

        # count
        cnt = 0
        for i, row in enumerate(g):
            for j, col in enumerate(row):
                if col is None:
                    if c[i][j] == '#':
                        cnt += 1

        if cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())


h,w,k = MI()
C = LS(h)

# pprint(C)

def mycalc(c):
    count = 0
    for i in range(h):
        for j in range(w):
            if c[i][j] == '#':
                count += 1
    return count

n = h+w
ans = 0
for i in range(2**n):
    c = deepcopy(C)
    for j in range(n):
        if i & (2**j):
            if j>=0 and j<h:
                c[j] = ['.']*w
            else:
                col = j - h
                for r in range(h):
                    c[r][col] = '.'
    # pprint(c)
    count = mycalc(c)
    if count == k:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
import copy
def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)
def check(s,n):
    if len(s) < n:
        d = n-len(s)
        for _ in range(d):
            s = '0'+s
    return s
ans = 0
H,W,K = inputlist()
maze = [[0] for _ in range(H)]
for i in range(H):
    maze[i] = list(input())
maza = copy.deepcopy(maze)
for i in range(2**H):
    xi = base10to(i,2)
    xi = check(xi,H)
    x_ = []
    for ind in range(H):
        if xi[ind] == "1":
            x_.append(ind)
    for j in range(2**W):
        yj = base10to(j,2)
        yj = check(yj,W)
        y_ = []
        for stu in range(W):
            if yj[stu] == "1":
                y_.append(stu)
        for x in x_:
            maze[x] = ["x" for _ in range(W)]
        for y in y_:
            for xa in range(H):
                maze[xa][y] = "x"
        count = 0
        for a in range(H):
            for b in range(W):
                if maze[a][b] == "#":
                    count+=1
        if count == K:
            ans +=1
        maze = copy.deepcopy(maza)

print(ans)

Submission status: Accepted

Solution code:
import copy

H,W,K = map(int,input().split())
C = [list(input()) for _ in range(H)]

M = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if C[i][j] == "#":
            M[i][j] = 1

def bit_01(keta):
    ans = []
    for i in range(2**(keta)):
        ans.append("".join(["{:0", str(keta), "b}"]).format(i))
    return ans

vert = bit_01(H)
hori = bit_01(W)

def check(v,h,M):
    M = copy.deepcopy(M)
    for i in range(len(v)):
        if v[i] == "1":
            for ii in range(W):
                M[i][ii] = 0
    for j in range(len(h)):
        if h[j] == "1":
            for jj in range(H):
                M[jj][j] = 0
    S = 0
    for i in range(W):
        for j in range(H):
            S += M[j][i]
    return S == K

ans = 0
for vp in vert:
    for hp in hori:
        if check(vp,hp,M):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
h,w,k = map(int,input().split())
s = []
for i in range(0,h):
    s.append(str(input()))
ans = 0
for bit_h in range(1 << h):
    for bit_w in range(1 << w):
        kuro = 0
        for tate in range(h):
            for yoko in range(w):
                if bit_h & (1 << tate) or bit_w & (1 << yoko):
                    kuro = kuro
                else:
                    if (s[tate])[yoko] == '#':
                        kuro += 1
        if kuro == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
import copy

h, w, k = map(int, input().split())
lst = []
for i in range(h):
    ci = list(input())
    lst.append(ci)

ans = 0
for htuple in itertools.product([0, 1], repeat=h):
    temp = copy.deepcopy(lst)
    for i in range(h):
        if htuple[i] == 1:
            temp[i] = ['r'] * w
    for wtuple in itertools.product([0, 1], repeat=w):
        wtemp = copy.deepcopy(temp)
        for j in range(w):
            if wtuple[j] == 1:
                for l in range(h):
                    wtemp[l][j] = 'r'
        current = 0
        for i in range(h):
            for j in range(w):
                if wtemp[i][j] == '#':
                    current += 1
        if current == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
row_sum = [0] * H
column_sum = [0] * W
A = []
for i in range(H):
  a = input()
  b = [0] * W
  for j in range(W):
    if a[j] == '#':
      row_sum[i] += 1
      column_sum[j] += 1
      b[j] = 1
  A.append(b)
A_sum = sum(column_sum)
ans = 0
for h in range(2**H):
  h_bit = format(h, 'b').zfill(H)
  row = []
  row_judge = 0
  for h_num, bit in enumerate(h_bit, 0):
    if bit == '1':
      row.append(h_num)
      row_judge += row_sum[h_num]
  for w in range(2**W):
    w_bit = format(w, 'b').zfill(W)
    column = []
    column_judge = 0
    for w_num, bit2 in enumerate(w_bit, 0):
      if bit2 == '1':
        column.append(w_num)
        column_judge += column_sum[w_num]
    matrix_judge = 0
    if row and column:
      for i in row:
        for j in column:
          matrix_judge -= A[i][j]
    if A_sum - (row_judge + column_judge + matrix_judge) == K:
      ans += 1
    # print(h_bit, row, w_bit, column)
    # print(A_sum, row_judge, column_judge, matrix_judge, ans)
print(ans)

Submission status: Accepted

Solution code:
import itertools as itr
import numpy as np

(h, w, k) = list(map(int, input().split(' ')))
field = [list(input()) for i in range(h)]

#print((h, w, k))
#print(field)

pattern_count = 0

for i in range(h):
    for j in range(w):
        r_combi = itr.combinations(range(h), i)
        for r in r_combi:
            c_combi = itr.combinations(range(w), j)
            for c in c_combi:
                row_deleted = np.delete(field, r, axis=0)
                deleted = np.delete(row_deleted, c, axis=1)
                count = np.sum(np.char.count(deleted, '#'))
                #print(r, c, count)
                if count == k:
                    pattern_count += 1

print(pattern_count)

Submission status: Accepted

Solution code:
import copy
H, W, K = list(map(int, input().split()))
matrix = [[0 for j in range(W)] for i in range(H)]
matrix2 = [[0 for j in range(W)] for i in range(H)]
for i in range(H):
    c_i = input()
    for j in range(W):
        if c_i[j] == '#':
            matrix[i][j] = 1
            matrix2[i][j] = 1
COUNT = 0
for i in range(2**(H+W)):
    x_i = []
    y_i = []
    count = 0
    for j in range(H+W):
        if ((i >> j) & 1):
            if j < H:
                x_i.append(j)
            else:
                y_i.append(j-H)
    for k in x_i:
        for l in range(W):
            matrix[k][l] = -1
    for k in range(H):
        for l in y_i:
            matrix[k][l] = -1
    for k in range(H):
        for l in range(W):
            if matrix[k][l] == 1:
                count += 1
    if count == K:
        COUNT += 1
    matrix = copy.deepcopy(matrix2)
print(COUNT)

Submission status: Accepted

Solution code:
from itertools import product

h, w, k = map(int, input().split())
c = [input() for _ in range(h)]

ans = 0

for row_bit in product(range(2), repeat=h):
    for col_bit in product(range(2), repeat=w):
        cnt = 0
        for row in range(h):
            for col in range(w):
                if (c[row][col] == '#') and ((row_bit[row] == 0) and (col_bit[col] == 0)):
                    cnt += 1   
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

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

c = [[] for _ in range(h)]

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

nh = 1 << h
nw = 1 << w

ans = 0

import copy
for i in range(nh):
    for j in range(nw):
        arr = copy.deepcopy(c)
        for x in range(h):
            if (i >> x) & 1:
                for t in range(w):
                    arr[x][t] = 'r'
        for y in range(w):
            if (j >> y) & 1:
                for t in range(h):
                    arr[t][y] = 'r'
        count = 0
        for x in range(h):
            for y in range(w):
                if arr[x][y] == '#':
                    count += 1
        if count == k:
            ans += 1
print(ans)

Submission status: Accepted

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

ans=0
for matR in range(2**H):
    for matC in range(2**W):
        cnt=0
        for i in range(H):
            for j in range(W):
                if (matR>>i)&1 and (matC>>j)&1:
                    if mat[i][j]=="#":
                        cnt+=1
        if cnt==K:
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
from itertools import product
import numpy as np

def main():
	h,w,k = map(int, input().split())
	c = np.array([[ 1 if j=='#' else 0 for j in input()] for i in range(h) ])
	ans = 0
	for row in product(range(2), repeat=h):
		for col in product(range(2), repeat=w):
			#print(row,col)
			e = np.array([[i*j for j in col] for i in row])
			if np.sum(c*e) == k:
				ans += 1
	print(ans)	

if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

for a in range(2**(h)):
    for x in range(2**w):
        black = 0
        for b in range(h):
            for y in range(w):
                if ((a >> b) & 1) and (x >> y & 1) and c[b][y] == '#':
                    black += 1
        if black == k:
            count += 1

print(count)

Submission status: Accepted

Solution code:
h, w, k = [int(x) for x in input().split()]

calc_table = [[0 for i in range(w)] for j in range(h)]
calc_total = 0
for i in range(h):
    line = [1 if x == '#' else 0 for x in list(input())]
    for j in range(w):
        calc_table[i][j] = line[j]
        calc_total += line[j]

num = 0
for hb in range(2**h):
    for wb in range(2**w):
        total = calc_total

        for i in range(h):
            selected_h = True if ((hb >> i) & 1) == 1 else False
            for j in range(w):
                selected_w = True if ((wb >> j) & 1) == 1 else False
                if selected_h or selected_w:
                    total -= calc_table[i][j]

        if total == k:
            num += 1

print(num)

Submission status: Accepted

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

ans = 0
for i in range(2 ** H):
    for j in range(2**W):
        c = 0
        for ci in range(H):
            for cj in range(W):
                if ((i >> ci) & 1) and ((j >> cj) & 1) and C[ci][cj] == '#':
                    c += 1
        if c == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
    H,W,K=MI()
    pixels = np.array([[0 for w in range(W)] for h in range(H)])
    tob = 0
    for h in range(H):
        C = IS()
        for w,c in enumerate(C):
            if c=='#':
                pixels[h][w] = 1
                tob+=1
    N=H+W
    M=2
    ans = 0
    r = np.array([0]*N)
    for i in range(M**N):
        ii = i
        for j in range(N):
            r[j] = ii % M;
            ii //= M
        if K==np.sum(pixels[np.ix_(r[0:H]>=1, r[H:]>=1)]):
            ans+=1
    print(ans)
            
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H,W,K = map(int,input().split())
c,ch,cw,a=[],[],[0]*6,0

for _ in range(H):
	t = input()
	c.append(t)
	ch.append(sum([x=='#' for x in t]))
for j in range(W):
	for i in range(H):
		if c[i][j] == '#':
			cw[j] += 1

for i in range(1<<H):
	for j in range(1<<W):
		s,si,sj=0,[],[]
		for d in range(H):
			if i & 1<<d:
				si.append(d)
				s += ch[d]
		for d in range(W):
			if j & 1<<d:
				sj.append(d)
				s += cw[d]
		for p in si:
			for q in sj:
				if c[p][q] == '#':
					s -= 1
		if sum(ch)-s == K:
			a += 1
print(a)

Submission status: Accepted

Solution code:
from itertools import product
import copy
h,w,k=map(int,input().split())
c = [[0]*w for i in range(h)]
for i in range(h):
    line = list(input())
    for j in range(w):
        if line[j]=='#':
            c[i][j]=1

ans = 0
for bit in product(range(2), repeat=h+w):
    cc = copy.deepcopy(c)
    #print(bit, end=' ')
    for i in range(h):
        if bit[i]==1:
            for j in range(w):
                cc[i][j] = 0
    for j in range(w):
        if bit[j+h]==1:
            for i in range(h):
                cc[i][j] = 0
    res = 0
    for i in range(h):
        res += sum(cc[i])
    #print(cc)
    if res==k:
        ans+=1
        #print('!!!!')
print(ans)

Submission status: Accepted

Solution code:
import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(list(dict.fromkeys(ans)))
    if(ans[-1]==n):
        ans = ans[:-1]
    return ans
h,w,k = map(int, input().split())
grid =[]
ans = 0
for i in range(h):
    grid.append(list(input()))
for mask1 in range(2**(h)):
    for mask2 in range(2**w):
        count = 0
        for r in range(h):
            for c in range(w):
                if(grid[r][c]!= '#'):
                    continue
                elif(((mask1>>r)&1) or((mask2>>c)&1)):
                    continue
                else:
                    count+=1
        if(count==k):
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

H,W,K=(int(x) for x in input().split())
c=[]
for i in range(H):
    c.append(input())
ans = 0
for maskR in range(1 << H):
    for maskC in range(1 << W):
        black = 0
        for i in range(H):
            for j in range(W):
                if ((maskR >> i) & 1) == 0 and ((maskC >> j) & 1) == 0 and c[i][j] == '#':
                        black = black + 1
        if black == K:
            ans = ans + 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
h,w,n=map(int, input().split())
l=[str(input())for _ in range(h)]
ans = 0

for i in list(itertools.product([0,1], repeat= h)):
    for j in list(itertools.product([0,1], repeat= w)):
        b = 0
        for k in range(h):
            for m in range(w):
                if i[k] == 0 and j[m] == 0 and l[k][m] == '#':
                    b +=1
        if b == n:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

H, W, K = map(int, input().split())
cells = np.zeros((H, W), dtype=np.int)

for i in range(H):
    tmp = input()
    for j in range(W):
        if tmp[j] == '#':
            cells[i][j] = 1

ans = 0

for mask_h in range(2**H):
    for mask_w in range(2**W):
        counter = 0
        for h in range(H):
            for w in range(W):
                if ((mask_h >> h) & 1) == 0 and ((mask_w >> w) & 1) == 0 and cells[h][w] == 1:
                    counter += 1

        if counter == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
H,W,K = map(int, input().split())
L=[]
for i in range(H):
    L.append(list(input()))
HH = 2**H
WW = 2**W

C=0

for i in range(HH):
    for i2 in range(WW):
        c=0
        hh = str(format(i,"b").zfill(H))
        ww = str(format(i2,"b").zfill(W))
        for h in range(H):
            for w in range(W):
                if hh[h]=="0" and ww[w]=="0":
                    if L[h][w]=="#":
                        c+=1
        if c==K:
            C+=1
print(C)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
cw = []
black_all = 0
for _ in range(H):
  s = input()
  cw.append(s)
  black_all += s.count("#")

ans = 0
for i in range(2 ** H):
  for j in range(2 ** W):
    bl = black_all
    for h in range(H):
      for w in range(W):
        if cw[h][w] == "#" and ((i // (2 ** h)) % 2 == 1 or (j // (2 ** w)) % 2 == 1):
          bl -= 1
    if bl == K:
      ans += 1
print(ans)