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=[input() for _ in range(H)]

ans=0
for i in range(1<<H):
    for j in range(1<<W):
        cnt=0
        for h in range(H):
            for w in range(W):
                if c[h][w]=='#':
                    if (i>>h)%2==0 and (j>>w)%2==0:
                        cnt+=1
        if cnt==K:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
h,w,K =  map(int,input().split())
masu = [input() for _ in range(h)]
ans = 0
for i in range(2**h):
    for j in range(2**w):
        cnt = 0
        for k in range(h):
            for l in range(w):
                if ((i >> k) & 1) and ((j >> l) & 1) and masu[k][l] == "#":
                    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)]
ans = 0
for i in range(1<<h):
    for j in range(1<<w):
        cnt = sum(c[k][l] == '#' for k in range(h) for l in range(w) if (i>>k & 1) and (j>>l & 1))
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
lis = []
ans = 0
for i in range(H):
  lis.append(list(input()))
for i in range(1<<H):
  for j in range(1<<W):
    cnt = 0
    for p in range(H):
      for q in range(W):
        if (i>>p) & 1:
          continue
        if (j>>q) & 1:
          continue
        if lis[p][q] == "#":
          cnt += 1
    if cnt == K:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
li=[]
for i in range(h):
  li.append(list(input()))
ans=0
for i in range(1<<h):
  for j in range(1<<w):
    cnt=0
    for p in range(h):
      for q in range(w):
        if i>>p&1:
          continue
        if j>>q&1:
          continue
        if li[p][q]=="#":
          cnt+=1
    if cnt==k:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
li=[]
for i in range(h):
  li.append(list(input()))
ans=0
for i in range(1<<h):
  for j in range(1<<w):
    cnt=0
    for p in range(h):
      for q in range(w):
        if i>>p&1:
          continue
        if j>>q&1:
          continue
        if li[p][q]=="#":
          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())
c = [input() for i in range(h)]
ans = 0
 
for maskR in product([0,1], repeat=h):
    for maskC in product([0,1], repeat=w):
        b = 0
        for i in range(h):
            for j in range(w):
                if maskR[i] == 1 and maskC[j] == 1 and c[i][j] == '#':
                    b += 1
        if b ==k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
ans = 0
for h in range(2**H):
    h = bin(h)[2:].zfill(H)
    for w in range(2**W):
        w = bin(w)[2:].zfill(W)
        cnt = 0
        for i in range(H):
            if h[i] == '1': continue
            for j in range(W):
                if w[j] == '1': continue
                if S[i][j] == '#':
                    cnt += 1
        
        if cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

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

c = [0] * h
for i in range(h):
    c[i] = input()
    
y = 0
    
for i in range(2 ** (h + w)):
    x = 0
    a = [0] * (h + w)
    for j in range(h + w):
        if (i // (2 ** j)) % 2 == 1:
            a[j] = 1
    
    for j in range(h):
        if a[j] == 0: 
            for l in range(w):
                if a[h+l] == 0:
                    if c[j][l] == '#':
                        x += 1
    
    if x == k:
        y += 1
        
print(y)

Submission status: Accepted

Solution code:
from itertools import product

h, w, k = map(int, input().split())
c = [list(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] and col_bit[col]):
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
    h, w, k = map(int, input().split())
    c = []
    for i in range(h):
        c.append(list(input()))

    ans = 0
    for i in range(2**h):
        for j in range(2**w):
            count = 0
            for ii in range(h):
                for jj in range(w):
                    if not (i >> ii & 1 or j >> jj & 1) and c[ii][jj] == "#":
                        count += 1
            if count == k:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools


def main():
    # n = int(input())
    h, w, k = map(int, input().split())
    # a = list(map(int, input().split()))
    # s = input()
    c = []
    for i in range(h):
        c.append(list(input()))

    total = 0
    for i in list(itertools.chain.from_iterable(c)):
        if i == "#":
            total += 1

    ans = 0
    for i in range(2**h):
        for j in range(2**w):
            count = 0
            for ii in range(h):
                for jj in range(w):
                    if (i >> ii & 1 or j >> jj & 1) and c[ii][jj] == "#":
                        count += 1
            if total - count == k:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for maskR in product([0,1], repeat=h):
    for maskC in product([0,1], repeat=w):
        b = 0
        for i in range(h):
            for j in range(w):
                if maskR[i]==1 and maskC[j]==1 and c[i][j]=="#":
                    b += 1
        if b == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import groupby, accumulate, product, permutations, combinations
h,w,k = map(int, input().split()) 
l = [input() for i in range(h)]
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from itertools import product
def main():
    h, w, k = map(int, input().split())
    gg = []
    for _ in range(h):
        row = [1 if c == '#' else 0 for c in list(input())]
        gg.extend(row)
    row_pro = tuple(product((0, 1), repeat=h))
    col_pro = tuple(product((0, 1), repeat=w))
    pat = tuple(product(row_pro, col_pro))
    r = 0
    for pate in pat:
        t0 = 0
        for i0, p0 in enumerate(pate[0]):
            for i1, p1 in enumerate(pate[1]):
                if p0 and p1:
                    t0 += gg[i0*w + i1]
        if t0 == k:
            r += 1
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from itertools import product
def main():
    h, w, k = map(int, input().split())
    gg = []
    for _ in range(h):
        row = [1 if c == '#' else 0 for c in list(input())]
        gg.extend(row)
    row_pro = tuple(product((0, 1), repeat=h))
    col_pro = tuple(product((0, 1), repeat=w))
    pat = tuple(product(row_pro, col_pro))
    r = 0
    for pate in pat:
        t0 = 0
        for i0, p0 in enumerate(pate[0]):
            for i1, p1 in enumerate(pate[1]):
                if p0 and p1:
                    t0 += gg[i0*w + i1]
        r += t0 == k
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from itertools import product
def main():
    h, w, k = map(int, input().split())
    gg = []
    for _ in range(h):
        row = [1 if c == '#' else 0 for c in list(input())]
        gg.extend(row)
    row_pro = tuple(product((0, 1), repeat=h))
    col_pro = tuple(product((0, 1), repeat=w))
    rows = []
    for re in row_pro:
        rows.append([i for i, b in enumerate(re) if b])
    cols = []
    for ce in col_pro:
        cols.append([i for i, b in enumerate(ce) if b])
    pat = tuple(product(rows, cols))
    r = 0
    for pate in pat:
        t0 = 0
        for p0 in pate[0]:
            for p1 in pate[1]:
                t0 += gg[p0*w + p1]
        if t0 == k:
            r += 1
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import itertools
import numpy as np

H, W, K = list(map(int, input().split()))
c_table = []

for _ in range(H):
    c_list = input()
    c_list = [0 if c == "." else 1 for c in list(c_list)]
    c_table.append(c_list)

h_patterns = list(itertools.product([True, False], repeat=H))
w_patterns = list(itertools.product([True, False], repeat=W))
count = 0
for h_p in h_patterns:
    for w_p in w_patterns:
        w_table = np.array(c_table)

        for i, h_flag in enumerate(h_p):
            if h_flag:
                w_table[i] = 0
            for j, w_flag in enumerate(w_p):
                if w_flag:
                    w_table.T[j] = 0
        if w_table.sum() == K:
            count += 1

ans = count

print(ans)

Submission status: Accepted

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

s = [list(map(str,list(input()))) for i in range(h)]
ans =0
for ii in range(1<<h):
    for jj in range(1<<w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if (ii >> i & 1):
                    continue
                if (jj >> j & 1):
                    continue
                if (s[i][j] == '#'):
                    cnt += 1

        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import copy

def count(w,h):
    Dtemp = copy.deepcopy(Data)

    for i in range(W):
        if ((1 << i) & w) != 0:
            for hh in range(H):
                Dtemp[hh][i] = 'R'
    for i in range(H):
        if ((1 << i) & h) != 0:
            for ww in range(W):
                Dtemp[i][ww] = 'R'
    c = 0
    for hh in range(H):
        for ww in range(W):
            if Dtemp[hh][ww] == '#':
                c += 1
    return c

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

ans = 0
for w in range(0,2**W):
    for h in range(0,2**H):
        if count(w,h) == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
h,w,K =  map(int,input().split())
masu = [input() for _ in range(h)]
ans = 0
for i in range(2**h):
    for j in range(2**w):
        cnt = 0
        for k in range(h):
            for l in range(w):
                if ((i >> k) & 1) and ((j >> l) & 1) and masu[k][l] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools
import copy

H,W,K = map(int,input().split())
c = [list(str(input())) for i in range(H)]
ans = 0
H_bit = list(itertools.product([0,1], repeat=H))
W_bit = list(itertools.product([0,1], repeat=W))

def mark(h,w,board):
    for i,n in enumerate(h):
        if n==1:
            board[i] = ["R"]*W
    for j,n in enumerate(w):
        if n==1:
            for k in range(H):
                board[k][j] = 'R'
    return board

for i in H_bit:
    for j in W_bit:
        check = copy.deepcopy(c)
        li = mark(i,j,check)
        if sum(a.count("#") for a in li)==K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
class HandV:
    def __init__(self, H, W, K, C):
        self.H = H
        self.W = W
        self.K = K
        self.C = C
        self.H_bar = [False] * H
        self.W_bar = [False] * W
        self.result = 0

    def solve(self):
        for i in range(2 ** self.H):
            for j in range(2 ** self.W):
                H_bar = [False] * self.H
                W_bar = [False] * self.W

                for n in range(H):
                    if (i & (2 ** n)) == 2 ** n:
                        H_bar[n] = True
                for n in range(W):
                    if (j & (2 ** n)) == 2 ** n:
                        W_bar[n] = True

                self.H_bar = H_bar
                self.W_bar = W_bar

                self.check()

    def check(self):
        black_count = 0
        for i in range(self.H):
            for j in range(self.W):
                if self.H_bar[i] or self.W_bar[j]:
                    continue
                if self.C[i][j] == "#":
                    black_count += 1
        if black_count == self.K:
            self.result += 1
 
H, W, K = map(int, input().split())

C = [ [None] * W for i in range(H) ]
for i in range(H):
    c_line = input()
    for j, c in enumerate(c_line):
        C[i][j] = c

handv = HandV(H, W, K, C)
handv.solve()
print(handv.result)

Submission status: Accepted

Solution code:
h,w,x=map(int,input().split())
a=[list(input()) for i in range(h)]
ans=0
for i in range(2**(h+w)):
  b=0
  for j in range(h):
    for k in range(w):
      if (i>>j)&1==1 and (i>>k+h)&1==1 and a[j][k]=="#":
        b+=1
  if b==x:
    ans+=1    
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

result = []
for n in range(len(board)+1):
    for conb in itertools.combinations(board, n):
        result.append(list(conb))

rotate_result = []
for i in range(len(result)):
    rotate_result.append([list(x) for x in zip(*result[i])])

ans = 0
result2 = []
for i in range(len(rotate_result)):
    for j in range(len(rotate_result[i])+1):
        for conb in itertools.combinations(rotate_result[i], j):
            result2.append(list(conb))
            l = list(itertools.chain.from_iterable(list(conb)))
            if l != []:
                count = 0
                for k in range(len(l)):
                    if l[k] == "#":
                        count += 1
                    if k == len(l)-1 and count == K:
                        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations

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

for i in range(h):
  row = [1 if x == '#' else 0 for x in input()]
  graph.append(row)

graph = np.array(graph)
h_combi = []
w_combi = []

for i in range(1, h + 1):
    h_combi.extend(list(combinations(range(h), i)))
for i in range(1, w + 1):
    w_combi.extend(list(combinations(range(w), i)))

ans = 0

for hi in h_combi:
  for wi in w_combi:
    cnt = 0
    for y in hi:
      if cnt > k:
        break
      for x in wi:
        cnt += graph[y][x]
    if cnt == k:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools

def main():
    H, W, K = map(int, input().split())
    C = [list(input().rstrip()) for _ in range(H)]
    ans = 0
    for h in itertools.product([0, 1], repeat=H):
        for w in itertools.product([0, 1], repeat=W):
            black = 0
            for r in range(H):
                for c in range(W):
                    if h[r] == 0 and w[c] == 0 and C[r][c] == "#":
                        black += 1
            if black == K:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for mask_h in range(2 ** H):
  for mask_w in range(2 ** W):
    black = 0
    for i in range(H):
      for j in range(W):
        if ((mask_h >> i) & 1 == 0) and ((mask_w >> j) & 1 == 0) and table[i][j] == '#': # 塗り潰し行、列ではなくて、色が黒'#'の場合
          black += 1

    if black == K:
      ans += 1
print(str(ans))

Submission status: Accepted

Solution code:

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

G = []
for _ in range(H):
    G.append(input())

ans = 0

black=0

for mask_h in range(1 << H):
    for mask_w in range(1 << W):
        black=0
        for i in range(H):
            for j in range(W):
                if((mask_h >> i) & 1 == 0 ) and ((mask_w >> j) & 1 == 0 ) and G[i][j] == '#':
                    black+=1
        if black == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
h,w,k = map(int,input().split())
c_list = []
for i in range(h):
  c_list.append(list(str(input())))
h_TF_list = []
w_TF_list = []
for i in range(2**h):
  p_m_list = [False for i in range(h)]
  for j in range(h):
    if ((i >>j) & 1):
      p_m_list[j] = True
  h_TF_list.append(p_m_list)
for i in range(2**w):
  p_m_list = [False for i in range(w)]
  for j in range(w):
    if ((i >>j) & 1):
      p_m_list[j] = True
  w_TF_list.append(p_m_list)
count = 0
for h_list in h_TF_list:
  for w_list in w_TF_list:
    p = 0
    for i in range(h):
      for j in range(w):
        if c_list[i][j] == "#" and h_list[i] == True and w_list[j] == True:
          p += 1
    if p == k:
      count += 1
print(count)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
from collections import Counter
import bisect
def main():
    H, W, K = MI()
    C = []
    for i in range(H):
        c = S()
        C.append(c)
    A = []
    for i in range(2 ** (H + W)):
        A_bit = []
        for j in range(H + W):
            # 二進数表記でj回右にシフトして0桁目（一番下の桁）が1であればTrue
            if ((i >> j) & 1):
                A_bit.append(j)
        A.append(A_bit)
    Ans_list = []
    for a in A:
        cnt = 0
        for i in range(H):
            if i in a:
                continue
            else:
                for j in range(H, W + H):
                    if j not in a and C[i][j - H] == '#':
                        cnt += 1
        Ans_list.append(cnt)
    ans = Counter(Ans_list)[K]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 0

for mask_r in range(1 << H):
    for mask_c in range(1 << W):
        black = 0
        for i in range(H):
            for j in range(W):
                if ((mask_r >> i) & 1 == 0) and ((mask_c >> j) & 1 == 0) and G[i][j] == "#":
                    black += 1
        if black == K:
            ans += 1

print(ans)

Submission status: Accepted

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

c = []
for i in range(H):
    c.append(list(input()))

ans = 0

for i in range(1<<H):
    for j in range(1<<W):
        v = 0
        for k in range(H):
            for l in range(W):
                if c[k][l] == '#' and i >> k & 1 == 0 and j >> l & 1 == 0:
                    v += 1
        if v == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math, sys

H,W,K = list(map(int, input().split()))

map=[]
Hs=[]
Ws=[]
for _ in range(H):
    row=list(input())
    map.append(row)
    Hs.append(row.count("#"))
for i in range(W):
    count=0
    for j in range(H):
        if map[j][i]=="#":
            count+=1
    Ws.append(count)
#print(Hs,Ws)
tot = sum(Hs)
ans=0
for i in range(2**H):
    for j in range(2**W):
        i_bin=(bin(i)[2:]).zfill(H)
        j_bin=(bin(j)[2:]).zfill(W)
        count=0
        for i2 in range(H):
            if i_bin[i2]=="1":
                count+=Hs[i2]
        for j2 in range(W):
            if j_bin[j2]=="1":
                count+=Ws[j2]
        for i2 in range(H):
            for j2 in range(W):
                if i_bin[i2]=="1" and j_bin[j2]=="1" and map[i2][j2]=="#":
                    count-=1
        if tot - count==K:
            ans+=1
            #print(i_bin,j_bin,count,tot-count)
print(ans)

Submission status: Accepted

Solution code:
H,W,K = map(int,input().split())
c = [tuple(input()) for i in range(H)]
ans = 0
for i in range(2**H):
    s = i
    b = [list(x) for x in c]
    for j in range(H):
        if s >= (2**(H-j-1)):
            s -= 2**(H-j-1)
            b[j] = ["."]*W
    b = list(zip(*b))
    for k in range(2**W):
        bt = [list(x) for x in b]
        t = k
        for l in range(W):
            if t >= (2**(W-l-1)):
                t -= 2**(W-l-1)
                bt[l] = ["."]*H
        u = sum(bt[m].count("#") for m in range(W))
        if u == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import itertools

H, W, K = map(int, input().split())
table = []

all = 0  # 黒の総計
row = [0] * H  # 各行の黒の数
column = [0] * W  # 各列の黒の数

for i in range(H):
    h_i = list(stdin.readline()[:-1])
    table.append(h_i)
    row[i] = h_i.count("#")
    all += row[i]

for j in range(W):
    for i in range(H):
        column[j] += table[i][j] == "#"

# print(row)
# print(column)

ans = 0
for x in range(H):  # 赤く塗る行の数
    for rs in itertools.combinations(range(H), x):  # 赤く塗る行の組み合わせ
        for y in range(W):  # 赤く塗る列の数
            for cs in itertools.combinations(range(W), y):  # 赤く塗る列の組み合わせ
                # print(f"row: {list(rs)}, colums: {list(cs)}", end=" ")
                painted = 0  # 塗られた黒の数
                for i in rs:
                    painted += row[i]
                for j in cs:
                    painted += column[j]
                for i in rs:
                    for j in cs:
                        painted -= table[i][j] == "#"  # 行と列の分を引き、重なったところが黒なら二重で引かないようにする
                if all - painted == K:
                    ans += 1

print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
c = [input() for _ in range(H)]
r = [[0]*W for _ in range(H)]
S = 0
for i in range(2**H):
  for j in range(2**W):
    cnt = 0
    for k in range(H):
      for l in range(W):
        if (i >> k) & 1:
          if (j >> l) & 1:
            if c[k][l] == "#":
              cnt += 1
    if cnt == K:
      S += 1
print(S)

Submission status: Accepted

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

field = [input() for _ in range(H)]

ans = 0
for i in range(1 << H):
    for j in range(1 << W):
        tmp = 0
        for i2 in range(H):
            for j2 in range(W):
                if (i >> i2) & 1: continue
                if (j >> j2) & 1: continue
                if field[i2][j2] != '#': continue
                tmp += 1
        if tmp == K: ans += 1

print(ans)

Submission status: Accepted

Solution code:
def bitmake(digit):#bit文字列生成（取り扱い注意）
    bit_list =list()

    for i in range(2 ** digit):
        bit = []
        for j in range(digit):  # このループが一番のポイント
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                bit.append(j)
        bit_list.append(bit)
    return bit_list
h,w,k = map(int,input().split())
grid = [""]*h
for i in range(h):
    grid[i] = list(map(str,input()))
# print(grid)

bit_list = bitmake(h+w)
# print(bit_list)
blackh = [0]*h#横
blackw = [0]*w#縦
blacksum = 0
for i in range(h):
    for j in range(w):
        if(grid[i][j] == "#"):
            blackh[i]+=1
            blackw[j]+=1
            grid[i][j] = 1
            blacksum += 1
        else:
            grid[i][j] = 0
# print(blackh,blackw)
ans = 0
for i in range(2**(h+w)):
    bit = bit_list[i]#h:0~(h-1),w:h~(h+w)-1
    remove = 0
    hight = []
    width = []
    for j in range(len(bit)):
        l = bit[j]
        if(l <= h-1):
            remove += blackh[l]
            hight.append(l)
        else:
            ind = l - h
            remove += blackw[ind]
            width.append(ind)
    # print(hight,width)
    rid = 0
    for j in range(len(hight)):
        for l in range(len(width)):
            if(grid[hight[j]][width[l]] == 1):
                rid += 1
    
    if((blacksum - remove) + rid == k):
        # print(blacksum,remove,rid,"___",blacksum-remove+rid)  
        ans += 1
print(ans)

# 2 3 2
# ..#
# ###

Submission status: Accepted

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

MAP=[[0 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        if List[i][j]=='#':
          MAP[i][j]=1

MAPP=[[0 for j in range(W)] for i in range(H)]
bx=[0]*W
by=[0]*H
c=[0]*2**H*2**W
for i in range(2**H*2**W):
    b=format(i,'b').zfill(H+W)
    for jx in range(W):
      bx[jx]=int(b[-W+jx])
    for jy in range(H):
      by[jy]=int(b[jy])
    for k in range(H):
      for l in range(W):
        MAPP[k][l]=MAP[k][l]*bx[l]*by[k]
    c[i]=sum(map(sum, MAPP))

print(c.count(K))

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):
        cnt = 0
        for h in range(H):
            for w in range(W):
                if((i >> h) & 1) == 0 and ((j >> w) & 1) == 0:
                    if C[h][w] == "#":
                        cnt += 1
        if cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b

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

    ans = 0
    for i in product([0, 1], repeat=H):
        for j in product([0, 1], repeat=W):
            black = 0
            for h in range(H):
                for w in range(W):
                    if i[h] == 1 and j[w] == 1 and c[h][w] == '#':
                        black += 1
            if black == K:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0

for i in range(2**h):
    for j in range(2**w):
        count = 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] == "#"):
                    count += 1
        if count == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
h,w,k = map(int,input().split())
lay = ['']*h
ans = 0
for i in range(h):
    lay[i] = input()
for i in range(2**h):
    for j in range(2**w):
        #行と列を選択した
        kuro = 0
        for i2 in range(h):
            if (i>>i2) & 1:
                for j2 in range(w):
                    if (j>>j2) & 1:
                        if lay[i2][j2] == '#':
                            kuro += 1
        if kuro == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
h,w,k=map(int, input().split())
Black = []
for i in range(h):
    c = input()
    for j in range(w):
        if c[j] == "#":
            Black.append((i,j))
# print(Black, len(Black))

ans = 0
for i in range(2 ** h):
    for j in range(2 ** w):
        a = len(Black)
        for b in Black:
            if ((i >> b[0]) & 1) or ((j >> b[1]) & 1):
            # if b[0] != i - 1 and b[1] != j - 1:
                a -= 1
        if a == k:
            ans += 1
            # print(bin(i),bin(j))
print(ans)

Submission status: Accepted

Solution code:
import itertools
h, w, k = map(int, input().split())
c = []
ans = 0
for i in range(h):
  c.append(list(input()))

for i in range(2 ** h - 1):
  c2 = []
  x = str(bin(i))[2:].zfill(h)
  for a in range(h):
    if x[a] == '0':
      c2.append(c[a])
    elif x[a] == '1':
      c2.append(['*'] * w)
  black = list(itertools.chain.from_iterable(c2)).count('#')
  for j in range(2 ** w - 1):
    black2 = black
    y = str(bin(j))[2:].zfill(w)
    for b in range(w):
      if y[b] == '1':
        for a in range(h):
          if c2[a][b] == '#':
            black2 -= 1
    if black2 == k:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    h,w,k = map(int,input().split())
    g = []
    for _ in range(h):
        g.append(input())
    
    ans = 0
    for hb in range(0b1<<h):
        for wb in range(0b1<<w):
            temp = 0
            for i in range(h):
                for j in range(w):
                    if 0b1&hb>>i and 0b1&wb>>j:
                        if g[i][j] == "#":
                            temp+=1
            
            if temp==k:
                ans+=1
    
    print(ans)
main()

Submission status: Accepted

Solution code:
def main():
    a,b,c = map(int,input().split())
    s =[list(map(str,input()))for i in range(a)]
    cnt =0
    count=0
    for i in range(2**a):
        for j in range(2**b):
            cnt=0
            for ia in range(a):
                for ib in range(b):
                    if not i &(1<<ia) and not j&(1<<ib):
                            if s[ia][ib] =='#':
                                cnt+=1
            if cnt ==c:
                count+=1
    print(count)
if __name__ =='__main__':
    main()