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())
a=[input() for _ in range(h)]
ans=0
for H in range(2**h):
    for W in range(2**w):
        c=0
        for i in range(h):
            for j in range(w):
                if H>>i&1 and W>>j&1 and a[i][j]=="#":
                    c+=1
        if c==k:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

res = 0

for r in range(1<<h):
    for g in range(1<<w):
        tmp = 0
        for i in range(h):
            for j in range(w):
                if c[i][j] == '#' and (r>>i)&1 == 1 and (g>>j)&1 == 1:
                    tmp += 1
        if tmp == k:
            res += 1

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

h,w,k = map(int,input().split())
M=[input().rstrip() for _ in range(h)]
ans = 0
for ib in range(1<<h):
    for jb in range(1<<w):
        cc = 0 
        for i in range(h):
            if ib&(1<<i):continue
            for j in range(w):
                if jb&(1<<j):continue
                cc+=M[i][j]=='#'
        if cc==k:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


H, W, K = MI()
C = [input() for _ in range(H)]

def count(red_x, red_y):
    cnt = 0
    for i in range(H):
        if i in red_x:
            continue
        for j in range(W):
            if j in red_y:
                continue
            if C[i][j] == '#':
                cnt += 1
    return cnt

ans = 0
for i in range(2 ** H):
    red_x = []
    for j in range(H):
        if (i >> j) & 1:
            red_x.append(j)
    for k in range(2 ** W):
        red_y = []
        for l in range(W):
            if (k >> l) & 1:
                red_y.append(l)
        if count(red_x, red_y) == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

ans = 0
for b1 in range(2**h):
    for b2 in range(2**w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if (b1 & (1 << i) == 0) and (b2 & (1 << j) == 0):
                    if s[i][j] == '#':
                        cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys

(h, w, k) = map(int, sys.stdin.readline().strip().split())

list_matrix = [sys.stdin.readline()[:-1] for _ in range(h)]

ans = 0
for check_row in range(1 << h):  # 左ビットシフトした値で上限を規定
    for check_column in range(1 << w):
        num_black = 0
        for i in range(h):
            for j in range(w):
                if (check_row >> i) & 1 == 0 and (check_column >> j) & 1 == 0 and list_matrix[i][j] == '#':
                    num_black += 1
        if num_black == k:
            ans += 1

print(ans)

Submission status: Accepted

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

ans = 0
for row in range(1 << H):
    R = set([i for i in range(H) if (row & (1 << i)) != 0])
    for col in range(1 << W):
        C = set([i for i in range(W) if (col & (1 << i)) != 0])

        cnt = 0
        for h in range(H):
            for w in range(W):
                if A[h][w] == '.' or h in R or w in C:
                    continue
                cnt += 1

        if cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
h,w,k=[int(x) for x in input().rstrip().split()]
tate=[]
yoko=[]
l=[]
ans=0
for i in range(h):
  c=[x for x in input()]
  l.append(c)
  bl=0
  for s in c:
    if s=="#":
      bl+=1
  yoko.append(bl)

for i in range(w):
  bl=0
  for j in range(h):
    if l[j][i]=="#":
      bl+=1
  tate.append(bl)

# print(tate)
# print(yoko)
for i in range(2**w):
  for j in range(2**h):
    now=0
    for ii in range(w):
      for jj in range(h):
        if j>>jj & 1 and i>>ii & 1:
          if l[jj][ii] == "#":
            now+=1
    if now==k:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
H,W,K=map(int,input().split())
s=[list(i)for i in [input() for i in range(H)]]
a=2**H-1
b=2**W-1
count=0
ans=0
for niti in range(2**(H+W)-1):
    count=0
    for i in range(H):
        for j in range(W):
            if niti>>i&1:
                continue
            if niti>>j+H&1:
                continue
            if s[i][j]=="#":
                count+=1
    if count==K:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
h,w,k = (int(a) for a in input().split())
g = [list(input()) for _ in range(h)]
ans = 0

for i in range(2**h) :
    for j in range(2**w) :
        c = 0
        for x in range(h) :
            for y in range(w) :
                if 2 ** x & i > 0 and 2 ** y & j > 0 :
                    if g[x][y] == "#" :
                        c += 1
        if c == 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(input())

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

print(ans)

Submission status: Accepted

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

ans = 0

for h in range(2**H-1):
    for w in range(2**W-1):
        black = 0
        for i in range(H):
            for j in range(W):
                if ((h>>i) & 1) == 0 and ((w>>j) & 1) == 0 and C[i][j] == '#':
                    black += 1
        if black == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

h,w,k = inpl()
s = [input() for _ in range(h)]
bl = sum(1 if x == '#' else 0 for i in range(h) for x in s[i])
res = 0
for yy in itertools.product([0,1], repeat = h):
    for xx in itertools.product([0,1], repeat = w):
        cnt = 0
        seen = set()
        for i,y in enumerate(yy):
            if y:
                for j in range(w):
                    if (i,j) in seen:
                        continue
                    seen.add((i,j))
                    if s[i][j] == '#':
                        cnt += 1
        for j,x in enumerate(xx):
            if x:
                for i in range(h):
                    if (i,j) in seen:
                        continue
                    seen.add((i,j))
                    if s[i][j] == '#':
                        cnt += 1
        if bl-cnt == k:
            res += 1
print(res)

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=map(int,input().split())
board=[list(input()) for _ in range(h)]
ans=0
for paint_h in range(2**h): #すべての行の塗りつぶし方を2進数で列挙する
    for paint_w in range(2**w): #すべての列の塗りつぶし方を2進数で列挙する
        cnt=0
        for i in range(h): #すべてのi行目j列目の要素についてみる
            for j in range(w):
                if (paint_h>>i)&1==0 and (paint_w>>j)&1==0: #各行のi番目のビットと各列のj番目のビットがともに0であればそのマスは塗りつぶされない
                    if board[i][j]=='#': #塗りつぶされないマスが黒マスであれば個数を+1する
                        cnt+=1
        if cnt==k: #塗りつぶされない黒マスの個数がKに等しければ答えを+1する
            ans+=1
print(ans)

Submission status: Accepted

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

    ans = 0
    for maskH in range((1 << H) - 1):
        for maskW in range((1 << W) - 1):
            black = 0
            for h in range(H):
                for w in range(W):
                    if (maskH >> h) & 1 == 0 and (maskW >> w) & 1 == 0 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 = [int(i) for i in input().split()]
C = []
for i in range(H):
    temp = list(input())
    C.append(temp)

    answer = 0
for row in range(2 ** H):
    for column in range(2 ** W):
        black = 0
        for i in range(H):
            for j in range(W):
                if (row >> i) % 2 == 1:
                    continue
                if (column >> j) % 2 == 1:
                    continue
                if C[i][j] == "#":
                    black += 1
        if black == K:
            answer += 1

print(answer)

Submission status: Accepted

Solution code:
import copy
h, w, k = map(int, input().split())
hw = []
mas = []
mas_su = 0

for i in range(h):
    hwi = input()
    masi = []
    for j in range(w):
        if hwi[j] == "#":
            masi.append(1)
        else:
            masi.append(0)

    mas_su += sum(masi)
    mas.append(masi)

l = 2**(h+w)
ans = 0

for i in range(l):
    test = copy.deepcopy(mas)
    num = 0
    for j in range(h+w):
        if ((i >> j) & 1):
            if j < h:
                for p in range(w):
                    if test[j][p]==1:
                        test[j][p] = 0
                        num += 1
            else:
                for p in range(h):
                    if test[p][j-h]==1:
                        test[p][j-h] = 0
                        num += 1
    if mas_su-num == 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()

cnt = 0

# ビット全探索
for rows in range(1 << h):
    for cols in range(1 << w):
        black = 0
        for i in range(h):
            if(rows >> i) % 2 == 1:
                continue
            for j in range(w):
                if(cols >> j) % 2 == 1:
                    continue
                black += c[i][j] == '#'
        if black == k:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import itertools
h, w, k = map(int, input().split())
table = [list(input()) for _ in range(h)]
ans = 0
for ptr_h in itertools.product([0, 1], repeat=h):
    for ptr_w in itertools.product([0, 1], repeat=w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if ptr_h[i] == 0 and ptr_w[j] == 0:
                    if table[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 _ in range(H)]
ans = 0

for I in range(2**H):
  for J in range(2**W):
    black = 0
    for i in range(H):
      for j in range(W):
        if (I>>i)&1 == 0 and (J>>j)&1 == 0 and c[i][j] == "#":
          black += 1
    if black == K:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
H, W, K = map(int, input().split())

maze = [list(input()) for i in range(H)]
ans = 0

for bith in range(1 << (H)):
    for bitw in range(1<<(W)):
                black = 0
                for i in range(H):
                    for j in range(W):
                        if ((bith >>i) & 1 ) & ((bitw >> j) & 1 ) & (maze[i][j] == "#") :
                           black += 1 
                if black == K:
                    ans += 1
                        # if bit & (1 << i)で、bitにiが含まれているか（フラグが立っているか）を判定してくれるらしい
print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
H, W, K = map(int, input().split())
g = [list(input()) for _ in range(H)]
# print(*g, sep="\n")
ans = 0
for h in range(2**H):
    for w in range(2**W):
        cnt = 0
        for i in range(H):
            for j in range(W):
                if (h >> i) & 1 == 0 and (w >> j) & 1 == 0 and g[i][j] == "#":
                    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 = [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):
        count = 0
        for h in range(H):
            for w in range(W):
                if c[h][w] == "#" and (row_bit[h] == 0 and col_bit[w] == 0):
                    count += 1
        if count == K:
            ans += 1


print(ans)

Submission status: Accepted

Solution code:
def nisin(a, L):
    nis = []
    for i in range(L):
        nis.insert(0, a%2)
        a = a//2
    return nis

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

ih = 0
ans = 0

while ih < 2**H:
    select_h = []
    bh = nisin(ih, H)
    iw = 0
    for i in range(H):
        if bh[i] == 0:
            select_h.append(i)
    while iw < 2**W:
        bw = nisin(iw, W)
        select_w = []
        for j in range(W):
            if bw[j] == 0:
                select_w.append(j)
        count = 0
        for u in range(H):
            for v in range(W):
                if u in select_h and v in select_w and C[u][v] == '#':
                    count += 1
        if count == K:
            ans += 1
        iw += 1
    ih += 1

print(ans)

Submission status: Accepted

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

count = 0
for i in range(2**h):
    for l in range(2**w):
        tmp = ""
        for j in range(h):
            for m in range(w):
                if ((i >> j) & 1) and ((l >> m) & 1):
                    tmp += C[j][m]
        if tmp.count("#") == k:
            count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

# bit全探索
count = 0
for cols in range(2**H):  # 全ての行の塗りつぶし方を2進数で列挙
    for rows in range(2**W):  # 全ての列の塗りつぶし方を2進数で列挙
        black = 0
        for i in range(H):
            for j in range(W):
                if (cols >> i) & 1 == 0 and (rows >> j) & 1 == 0:
                    black += cw[i][j] == '#'
        if black == K:
            count += 1
print(count)

Submission status: Accepted

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

for rows in range(1 << h):
  for cols in range(1 << w):
    black = 0
    for i in range(h):
      if (rows >> i) & 1:
        continue
      for j in range(w):
        if (cols >> j) & 1:
          continue
        black += c[i][j] == "#"
    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):
    row = list(input())
    C.append(row)

#print(C)

pattern = 0

for markR in range(1<<H):
    for markC in range(1<<W):
        black = 0
        for i in range(H):
            for j in range(W):
                if (markR>>i) & 1 == 0 and (markC>>j) & 1 == 0 and C[i][j] == "#":
                    black += 1
        if black == K:
            pattern += 1

print(pattern)

Submission status: Accepted

Solution code:
H, W, K = map(int,input().split())
masu = []
subete = 0
yoko = [0]*H
tate = [0]*W
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == '#':
            yoko[i] += 1
            tate[j] += 1
            subete += 1

    masu.append(s)

kotae = 0

for i in range(2**(H+W)):
    nuri = bin(i)[2:]
    ans = 0 + subete

    while len(nuri) < H+W:
        nuri = '0' + nuri 
    for j in range(H+W):
        if nuri[j] == '1':
            if j < H:
                ans -= yoko[j]
                for l in range(H,H+W):
                    if nuri[l] == '1':
                        if masu[j][l-H] == '#':
                            ans += 1
            if H <= j:
                ans -= tate[j-H]
    if ans == K:
        kotae += 1

     


print(kotae)

Submission status: Accepted

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

  result = 0
  for i in range(1 << h):
    for j in range(1 << w):
      cnt = 0
      for n in range(h):
        if i >> n & 1:
          continue

        for m in range(w):
          if j >> m & 1:
            continue

          if C[n][m] == '#':
            cnt += 1

      if cnt == k:
        result += 1

  print(result)


if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    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 = 0
            for a in range(H):
                for b in range(W):
                    if not (i >> a & 1 or j >> b & 1) and C[a][b] == '#':
                        cnt += 1
            if cnt == K:
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import numpy as np


def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    h, w, k = map(int, input().split())
    css = np.array([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 css[i][j] == '#':
                            cnt += 1
            if cnt == k:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
h,w,k = map(int,input().split())
c = np.zeros((h,w))
for _ in range(h):
  row = [1 if a=='#' else 0 for a in input()]
  c[_]=row
ans = 0
for bit in range(1<<h+w):
  d = np.copy(c)
  for i in range(h+w):
    if (bit>>i)&1:
      if i<h:
        d[i]=0
      else:
        d[:,i-h]=0
  if np.sum(d)==k:
    ans += 1
print(ans)

Submission status: Accepted

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

ans = 0

for h_bin in range(1 << h):
    for w_bin in range(1 << w):
        black_cnt = 0
        for i in range(h):
            for j in range(w):
                if (h_bin >> i & 1) == 1 and (w_bin >> j & 1) == 1 and l[i][j] == '#':
                   black_cnt += 1
        if k == black_cnt:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


h, w, k = LI()
C = SR(h)
ans = 0
for i in range(2 ** (h + w)):
    ret = 0
    for y in range(h):
        for x in range(w):
            if i >> y & 1 and i >> (h + x) & 1 and C[y][x] == "#":
                ret += 1
    if ret == k:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import copy
def get_list(n):
  l = []
  for _ in range(6):
    if n & 0x01: l.append(1)
    else:l.append(0)
    n=n >> 1
  #l.reverse()
  return l

def count_black(l,h,w):
  res=0
  for _h in range(h):
    for _w in range(w):
      if l[_h][_w]=='#':res+=1
#    res+=l[_h].count('#')
  return res

def main():
  H,W,K=map(int,input().split())
  c=[list(input()) for _ in range(H)]
  max_h,max_w=2**H-1,2**W-1
  ans=0
  for h2 in range(max_h):
    for w2 in range(max_w):
      count_black=0
      for h in range(H):
        for w in range(W):
          if (h2 >> h & 1) or (w2 >> w & 1):
            # to Red
            pass
          else:
            if c[h][w]=='#':
              count_black+=1
      if count_black==K: ans+=1
  print(ans)
  pass
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import copy
import itertools

def main():
    H, W, K = map(int, input().split())
    # あとで足し算で計算するので#は1にそれ以外は0へ
    C = [[1 if v == '#' else 0 for v in input()] for _ in range(H)]
    ans = 0
    # 選んだところは0に塗り直す
    for x in range(2**H):
        for y in range(2**W):
            cnt = 0
            c = copy.deepcopy(C)
            for h in range(H):
                if(x >> h) & 1:
                    for w in range(W):
                        c[h][w] = 0
            for w in range(W):
                if(y >> w) & 1:
                    for h in range(H):
                        c[h][w] = 0
            # flatten
            cnt = sum(list(itertools.chain.from_iterable(c)))
            if cnt == 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)]
ans = 0

for rows in range(1 << h):
    for cols in range(1 << w):
        cnt = 0
        for i in range(h):
            if (rows >> i) & 1: continue
            for j in range(w):
                if (cols >> j) & 1:
                    continue
                else:
                    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()) 
L = [list(input()) for i in range(H)]
from itertools import product
li = [0,1]
ans = 0
for h in product(li,repeat = H):
    for w in product(li,repeat = W):
        cnt = 0
        for j in range(H):
            for i in range(W):
                if h[j] == 0 and w[i] == 0:
                    if L[j][i] == "#":
                        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())
grid = [input() for _ in range(H)]

ans = 0
for row in product([0, 1], repeat=H):
    for col in product([0, 1], repeat=W):
        cnt = 0
        for i in range(H):
            for j in range(W):
                # 当該のマス(i, j)が赤く塗られておらず かつ 黒色のとき
                if row[i] and col[j] and grid[i][j] == '#':
                    cnt += 1
        if cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
H,W,K =map(int,input().split()) 
L = [list(input()) for i in range(H)]
ans = 0
for h in range(1<<H):
    for w in range(1<<W):
        cnt = 0
        for j in range(H):
            for i in range(W):
                if h>>j&1 == 0 and w>>i&1 == 0:
                    if L[j][i] == "#":
                        cnt +=1
        if cnt == K:
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

H,W,K=map(int,input().split())
b=[]
for i in range(H):
    _=input()
    temp=_.replace('#','1').replace('.','0')
    b.append(list(map(int,temp)))

area=np.array(b)

ans=0

for h in range (2**H):
    select_H=[] #削除する行の組合わせを取得

    for i in range (H):
        if (h>>i) & 1==1:
            select_H.append(1)
        else:
            select_H.append(0)
    sHarr=np.array(select_H)
    delsHarr=np.where(sHarr==1) #削除する行のindexを取得
    area_afterDelsH=np.delete(area,delsHarr,axis=0) #エリアから行を削除する。
            # 以下、行が削除された各パターンについて、列を削除していく。

    for w in range (2**W):
        select_W=[] #削除する列の組合わせを取得
        for j in range (W):
            if (w>>j) &1 ==1:
                select_W.append(1)
            else:
                select_W.append(0)
        sWarr=np.array(select_W)
        delsWarr=np.where(sWarr==1) #削除する列のindexを取得
        area_afterDelsHsW=np.delete(area_afterDelsH,delsWarr,axis=1)

        if np.sum(area_afterDelsHsW)==K:
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
matrix = [input() for _ in range(H)]
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 matrix[i][j] == "#":
					black += 1

		if black == K:
			ans += 1

print(ans)

Submission status: Accepted

Solution code:
h,*c=open(0)
h,w,k=map(int,h.split())
print(sum(k==sum(y>>w+z//w&y>>z%w&('.'>c[z//w][z%w])for z in range(h*w))for y in range(1<<h+w)))

Submission status: Accepted

Solution code:
from itertools import product

def input2():
	return map(int,input().split())
  
h,w,k=input2()
C=[list(input()) for _ in range(h)]





ans=0

for row_bit in product(range(2),repeat=h): #[行]0:赤なし，1:赤あり
	for col_bit in product(range(2),repeat=w): #[列]0:赤なし，1:赤あり
		count=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):
					count+=1
		if count==k:
			ans+=1
print(ans)

Submission status: Accepted

Solution code:
H,W,K = [int(x) for x in input().split()];
c=[];
for i in range(H) :
    c.append(input());
#h = bin(2**H);
#w = bin(2**W);
cnt =0;
for i in range(2**H) :
    for j in range(2**W) :
        k = 0;
        for x in range(H) :
            for y in range(W) :
                idxx = (i >> x)%2;
                idxy = (j>>y)%2;
                if c[x][y] == '#' and idxx == 0 and idxy == 0 :
                    k = k +1;
        if k == K :
            cnt = cnt + 1;
print(cnt);

Submission status: Accepted

Solution code:
import copy

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

c = []
for i in range(1, h+1):
  l = input()
  for j in range(len(l)):
    if l[j] == "#":
      c.append((i, j+1))

combs = []
n_comb = 2**(h+w)
for n in range(n_comb):
  combs.append(format(n, f"0{h+w}b"))

for comb in combs:
  cc = copy.copy(c)
  h_choice = comb[:h]
  w_choice = comb[h:]
  for n, i in enumerate(h_choice):
    if i == "1":
      cc = [cell for cell in cc if cell[0] != n+1]
  for n, j in enumerate(w_choice):
    if j == "1":
      cc = [cell for cell in cc if cell[1] != n+1]
      
  if len(cc) == k:
    ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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

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

ans = 0

#塗られてない行と列を列挙し、そこに黒がどんだけあるか数える。
for i in range(H+1):
    for j in range(W+1):
        for sh in combinations(range(H), i):
            for sw in combinations(range(W), j):
                v = 0
                for h in sh:
                    for w in sw:   
                        if field[h][w] == '#':
                            v += 1
                if v == K:
                    ans += 1            
print(ans)

Submission status: Accepted

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

h, w, k = map(int, input().split())
c = [input() for i in range(h)]
ans = 0
for si in range(2 ** h):
    for sj in range(2 ** w):
        count = 0
        for i in range(h):
            for j in range(w):
                if si>>i & 1:
                    continue
                if sj>>j & 1:
                    continue
                if c[i][j] == "#":
                    count += 1
        if count == k:
            ans += 1
print(ans)