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())
# l = []
# s = 0

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

# l_sum = sum(map(sum, l))


# for i in range(h):
#     for j in range(w):
# print("")

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であればそのマスは塗りつぶされない
                    cnt += board[i][j] == "#"  # 塗りつぶされないマスが黒マスであれば個数を+1する
        ans += cnt == k  # 塗りつぶされない黒マスの個数がKに等しければ答えを+1する
print(ans)

Submission status: Accepted

Solution code:
n,m,k = map(int,input().split())
ans = 0
g = [[i for i in input()] for i in range(n)]

for maskY in range(1 << n):
   ng = [[0]*m for i in range(n)]
   for bit in range(n):
       if maskY & (1 << bit):
           for i in range(m):
               ng[bit][i] = 1
   for maskX in range(1 << m):
       ngg = [[i for i in j] for j in ng]
   #    print(ngg)
       for bit in range(m):
           if maskX & (1 << bit):
               for i in range(n):
                   ngg[i][bit] = 1
       cnt = 0
       for y in range(n):
           for x in range(m):
               if g[y][x]=="#" and ngg[y][x]==0:
                   cnt += 1
   #    print(cnt)
       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
import itertools
tf=("Yes", "No")
l=list(itertools.product(tf, repeat=(H+W)))
black=0
for i in range(2**(H+W)):
  for j in range(H):
    for k in range(W):
      if l[i][j]=="No"and l[i][H+k]=="No"and C[j][k]=="#":
        black+=1
  if black==K:
    ans+=1
  black=0
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

h,w,k = map(int,input().split())
mat = [input() for i in range(h)]
r = [0 for i in range(h)]
c = [0 for i in range(w)]
black = 0
for i in range(h):
    for j in range(w):
        if mat[i][j]=="#":
            r[i] += 1
            c[j] += 1
            black += 1

ans = 0
for i in range(h):
    for combr in combinations(range(h),i):
        for j in range(w):
            for combc in combinations(range(w),j):
                temp = 0
                for x in combr:
                    temp += r[x]
                for y in combc:
                    temp += c[y]
                overlap = 0
                for x in combr:
                    for y in combc:
                        if mat[x][y]=="#":
                            overlap += 1
                if black+overlap-temp==k:
                    ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

h,w,k = map(int,input().split())
mat = [input() for i in range(h)]
r = [0 for i in range(h)]
c = [0 for i in range(w)]
black = 0
for i in range(h):
    for j in range(w):
        if mat[i][j]=="#":
            r[i] += 1
            c[j] += 1
            black += 1

ans = 0
for i in range(h):
    for combr in combinations(range(h),i):
        for j in range(w):
            for combc in combinations(range(w),j):
                temp = 0
                for x in combr:
                    temp += r[x]
                for y in combc:
                    temp += c[y]
                overlap = 0
                for x in combr:
                    for y in combc:
                        if mat[x][y]=="#":
                            overlap += 1
                if black+overlap-temp==k:
                    ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, w, k = [int(i) for i in input().split()]
l = []
cnt = 0
for _ in range(n):
  l.append(list(input()))
import itertools
for w_ in itertools.product((True, False), repeat=w):
  for n_ in itertools.product((True, False), repeat=n):
    cnt_ = 0
    for i in range(w):
      for j in range(n):
        if w_[i] and n_[j] and l[j][i] == '#':
          cnt_ += 1
    if cnt_ == k:
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import itertools
from typing import List


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

    print(hv(c, h, w, k))


def hv(c: List[List[str]], h: int, w: int, k: int) -> int:
    ret = 0
    for comb_h in itertools.product((False, True), repeat=h):
        for comb_w in itertools.product((False, True), repeat=w):
            cnt = 0
            for i in range(h):
                for j in range(w):
                    if comb_h[i] and comb_w[j] and c[i][j] == '#':
                        cnt += 1
            if cnt == k:
                ret += 1
    return ret


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# ------------------- fast io --------------------
from math import gcd, ceil
 
def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi
 
 
def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans
 
def lcm(a, b): return a * b // gcd(a, b)
 
 
def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y





def solve(h, w, k, board):
    ans = 0
    for row in range(1 << h):
        for col in range(1 << w):
            count = 0
            for i in range(h):
                for j in range(w):
                    if (row >> i) & 1 == 0:
                        continue
                    if (col >> j) & 1 == 0:
                        continue
                    if board[i][j] == '#':
                        count += 1
            if count == k:
                ans += 1
    return ans





h, w, k = map(int, input().split())
board = []
for i in range(h):
    board += [list(input())]
print(solve(h, w, k, board))

Submission status: Accepted

Solution code:
h, w, k = list(map(int, input().split()))
m = []

for i in range(h):
    m.append(input())

def count(h, w):
    cnt = 0
    for i in h:
        for j in w:
            if m[i][j] == '#': cnt += 1
    return cnt

def remove(l, x):
    return [y for y in l if y is not x]

def search(hs, ws, hmin, wmin):
    nblack = count(hs, ws)
    if nblack < k:
        return 0

    res = 0
    if wmin == 0:
        for i in range(hmin, h):
            hs_ = remove(hs, i)
            res += search(hs_, ws, i + 1, wmin)

    for j in range(wmin, w):
        ws_ = remove(ws, j)
        res += search(hs, ws_, hmin, j + 1)

    if nblack == k:
        return res + 1
    return res

x = search(list(range(h)), list(range(w)), 0, 0)
print(x)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split(' '))
ls, rst = [], 0
for i in range(H):
    ls.append(input())
for i in range(1 << H):
    for j in range(1 << W):
        cnt = 0
        for s in range(H):
            if i >> s & 1:
                continue
            for t in range(W):
                if j >> t & 1:
                    continue
                if ls[s][t] == '#':
                    cnt += 1
        if cnt == K:
            rst += 1
print(rst)

Submission status: Accepted

Solution code:
h,w,k = map(int,input().split())
c = []
for i in range(0,h):
    c.append(input())
def white(c,r,co):
    count = 0
    for i in range(0,h):
        for j in range(0,w):
            if r[i] != 0 and co[j] != 0 and c[i][j] == "#":
                count += 1            
    return count
import itertools
listr = list(itertools.product([0,1],repeat = h))
listc = list(itertools.product([0,1],repeat = w))
ans = 0
for i in range(0,2**h):
    for j in range(0,2**w):
        if white(c,listr[i],listc[j]) == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
	H, W, K = [int(k) for k in input().split(" ")]
	C = []
	black_in_row = []
	black_in_col = [0] * W
	for i in range(H):
		C.append(list(input()))
		black_in_row.append(C[i].count("#"))
		for j in range(W):
			if C[i][j] == "#":
				black_in_col[j] += 1

	black = sum(black_in_row)
	if black < K:
		print(0)
		return 0

	cnt = 0
	for i in range(2 ** H):
		row_bit = [f for f, b in enumerate(list(pad_zero(format(i, 'b'), H))) if b == "1"]
		r = sum([black_in_row[y] for y in row_bit])
		for j in range(2 ** W):
			col_bit = [f for f, b in enumerate(list(pad_zero(format(j, 'b'), W))) if b == "1"]
			c = sum([black_in_col[x] for x in col_bit])
			bl = black - r - c + sum([1 for p in row_bit for q in col_bit if C[p][q] == "#"])
			if bl == K:
				cnt += 1
	print(cnt)


def pad_zero(s, n):
	s = str(s)
	return ("0" * n + s)[-n:]

main()

Submission status: Accepted

Solution code:
h,w,k = map(int,input().split())
A = [list(input()) for _ in range(h)]
ans = 0
for i in range(2**w):
    for j in range(2**h):
        grid = [k[:] for k in A]
        cnt = 0
        for p in range(h):
            if (j >> p) & 1:
                grid[p] = ["r"]*w
        for q in range(w):
            if (i >> q) & 1:
                for b in grid:
                    b[q] = "r"
        for x in grid:
            cnt += x.count("#")
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int,input().split())
grid = [list(input()) for _ in range(h)]
ans = 0
# 全行、全列のパターンを全探索
for h_red in range(2**h):
    for w_red in range(2**w):
        
        cnt = 0
        # 前段の2つのfor文で、全パターンについて探索するので、
        # この後の2つのfor文で、パターン毎の#の数をカウントする
        for i in range(h):
            for j in range(w):
                
                # この課題で、一番大事なロジックはここである。
                # ビット演算子>>右シフトと論理積&を組み合わせている
                # h_redやw_redは10進数であるが2進数の場合におけるi、jだけ右にシフトさせる
                # このi、jは10進数扱いであることがややこしい
                # i、jが一周するときに、h_red、w_redをなめているところがポイント
                if (h_red>>i)&1 == 0 and (w_red>>j)&1 == 0:
                    if grid[i][j] == '#':
                        cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
H,W,K=map(int,input().split())
c=[str(input())for i in range(H)]
ans=0
for maskH in range(2**H):
    for maskW in range(2**W):
        black=0
        for i in range(H):
            for j in range(W):
                if ((maskH>>i)&1)==1:
                    continue
                if ((maskW>>j)&1)==1:
                    continue
                if c[i][j]=='#':
                    black+=1
        if black==K:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import copy
 
H, W, K = map(int, input().split())
tiles = [list(input()) for _ in range(H)]
answer  = 0

for h in range(2**H):
  for w in range(2**W):
    b_cnt = 0
    for i in range(H):
      for j in range(W):
        if not (h>>i&1 or w>>j&1) and tiles[i][j] == '#':
          b_cnt += 1
    if b_cnt == K:
      answer += 1
print(answer)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
fi = []
for _ in range(H):
    s = input()
    fi.append(s)
a = 2 ** H
b = 2 ** W
total = 0

for i in range(a * b):
    lh = list()
    lw = list()

    for j in range(H):
        if i & (1 << j):
            lh.append(1)
        else:
            lh.append(0)
    for j in range(W):
        if i & (1 << (j + H)):
            lw.append(1)
        else:
            lw.append(0)
    # print(lh)
    # print(lw)

    cnt = 0
    for j in range(H):
        for l in range(W):
            if lh[j] == 1 or lw[l] == 1:
                continue
            if fi[j][l] == '#':
                cnt += 1
    # print(cnt)
    if cnt == K:
        total += 1

print(total)

Submission status: Accepted

Solution code:
import copy
from collections import Counter

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



c = [[False for _ in range(w)] for _ in range(h)]
for i in range(h):
    s = input()
    for j in range(len(s)):
        if s[j] == '#':
            c[i][j] = True


cnt = 0
for i in range(2**h):
    tmp = copy.deepcopy(c)
    for j in range(h):
        if((i >> j) & 1):
            tmp[j] = [False for _ in range(w)] 

    for k in range(2**w):
        tmp2 = copy.deepcopy(tmp)
        for m in range(w):
            if((k >> m) & 1):
                for a in range(h):
                    tmp2[a][m] = False
            
        if sum(tmp2, []).count(True) == K:
            cnt += 1

print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(1 << h):
    for j in range(1 << w):
        black = 0
        for x in range(h):
            for y in range(w):
                if (i >> x) & 1:
                    continue
                    
                if (j >> y) & 1:
                    continue
                    
                if c[x][y] == '#':
                    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 i in range(h)]

ans = 0
for i in range(2 ** h):
    for j in range(2 ** w):
        black = 0
        for x in range(h):
            for y in range(w):
                if (i >> x) & 1:
                    continue
                    
                if (j >> y) & 1:
                    continue
                    
                if c[x][y] == '#':
                    black += 1
        if black == k:
            ans += 1
print(ans)

Submission status: Accepted

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

cnt = 0

for h in range(1 << H):
    for w in range(1 << W):
        black = 0

        for i in range(H):
            if (h >> i) % 2 == 1:
                continue
            for j in range(W):
                if (w >> j) % 2 == 1:
                    continue

                black += cell[i][j] == '#'
        
        cnt += black == k

print(cnt)

Submission status: Accepted

Solution code:
WHITE = '.'
BLACK = '#'

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

ans = 0
for rows in range(2 ** H):
    for cols in range(2 ** W):
        cnt = 0
        for h in range(H):
            for w in range(W):
                if (rows >> h) & 1 or (cols >> w) & 1:
                    continue
                cnt += C[h][w] == BLACK
        if cnt == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
h,w,y=map(int,input().split())
c=[input() for _ in range(h)]
black=0
for i in range(h):
    for j in range(w):
        if c[i][j]=="#":
            black+=1
if black<y:
    print("0")
    exit()
hb=[]
wb=[]
for i in range(h):
    hb.append(c[i].count("#"))
for i in range(w):
    count=0
    for j in range(h):
        if c[j][i]=="#":
            count+=1
    wb.append(count)
bit=[]
for i in range(2**(h+w)): #行：[:h]、列：[h+1:]
    bit.append(bin(i)[2:].zfill(h+w))
ans=0
for i in bit:
    x=black
    for j in range(h):
        if i[j]=="1":
            for k in range(w):
                if i[h+k]=="1" and c[j][k]=="#":
                    x+=1
    for j in range(h):
        if i[j]=="1":
            x-=hb[j]
    for j in range(w):
        if i[h+j]=="1":
            x-=wb[j]
    if x==y:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
def solve():
    H,W,K = [int(i) for i in input().split()]
    grids = []
    for i in range(H):
        row = input()
        grids.append(row)

    import itertools
    rows = list(range(H))
    row_combis = set([])
    for i in range(H+1):
        tmp = itertools.combinations(rows, i)
        row_combis |= set(tmp)
    columns = list(range(W))
    column_combis = set([])
    for i in range(W+1):
        tmp = itertools.combinations(columns, i)
        column_combis |= set(tmp)

    ans = 0
    for row_combi in row_combis:
        for column_combi in column_combis:
            num_black = 0
            for i in range(H):
                for j in range(W):
                    if i in row_combi:
                        continue
                    if j in column_combi:
                        continue
                    if grids[i][j] == '#':
                        num_black += 1
            if num_black == K:
                ans += 1
    print(ans)


if __name__ == "__main__":
    solve()

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 = 0
        for x in range(H):
            for y in range(W):
                if (i>>x)&1==1 and (j>>y)&1 and c[x][y] == '#':
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split(' '))
ls, rst = [], 0
for i in range(H):
    ls.append(input())

for i in range(1 << H):
    for j in range(1 << W):
        cnt = 0
        for s in range(H):
            if i >> s & 1:
                continue
            for t in range(W):
                if j >> t & 1:
                    continue
                if ls[s][t] == '#':
                    cnt += 1
        if cnt == K:
            rst += 1
print(rst)

Submission status: Accepted

Solution code:
H, W, K = [int(x) for x in input().split()]

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

ans = 0
for h in range(2 ** H, 2 ** H + 2 ** H):
    bin_h = format(h, 'b')[1:]
    for w in range(2 ** W, 2 ** W + 2 ** W):
        bin_w = format(w, 'b')[1:]
        count = 0
        for i in range(H):
            for j in range(W):
                if bin_h[i] == '0' and bin_w[j] == '0' and C[i][j] == '#':
                    count += 1
        if count == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
## H, Kの値が小さいので塗り方の全ての通りを調べる方針でよい(全探索)
## 各塗り方について全てのマスが黒いかどうか調べて、黒いマスがK個あればよい
## itertoolsモジュールを使ってみる
from itertools import product
H, W, K = (int(x) for x in input().split())
C = [list(input()) for _ in range(H)] #H行〇列の行列を格納する
answer = 0

for row_bit in product(range(2), repeat=H):
#"product(range(2), repeat=H)"で長さがHで、各要素が1か0であるすべての組み合わせがすべて列挙される.
## cf.) https://docs.python.org/ja/3/library/itertools.html#itertools.product
    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:
            answer += 1
print(answer)
## 参考 : https://qiita.com/u2dayo/items/90a0693f31524e7b4cd0#c%E5%95%8F%E9%A1%8Ch-and-v

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

h,w,k=nii()
c=[list(input()) for i in range(h)]

b_cnt=0
for i in c:
  b_cnt+=i.count('#')

ans=0
for i in range(2**h):
  for j in range(2**w):
    h_use=[]
    for ii in range(h):
      if (i>>ii)&1:
        h_use.append(ii)
    w_use=[]
    for jj in range(w):
      if (j>>jj)&1:
        w_use.append(jj)

    t_cnt=0
    for s in h_use:
      t_cnt+=c[s].count('#')
    for s in w_use:
      for t in range(h):
        if c[t][s]=='#':
          t_cnt+=1

    for s in h_use:
      for t in w_use:
        if c[s][t]=='#':
          t_cnt-=1

    if b_cnt-t_cnt==k:
      ans+=1

print(ans)

Submission status: Accepted

Solution code:
from itertools import product

h, w, k = map(int, input().split())
AL = []
count = 0
for i in range(h):
    c = list(input())
    AL.append(c)
for a in product(range(2), repeat=h):
    for b in product(range(2), repeat=w):
        black = 0
        for i in range(h):
            for j in range(w):
                if AL[i][j] == "#" and (a[i] and b[j]):
                    black += 1
        if k == black:
            count += 1
print(count)

Submission status: Accepted

Solution code:
#C for submisstion
import numpy as np
from itertools import combinations
H, W, K = map(int, input().split())
C=[input() for i in range(H)]
C_list=[list(C[i]) for i in range(H)]
C_cols=['c'+str(i) for i in range(H)]
C_rows=['r'+str(i) for i in range(W)]
C_comb=C_cols + C_rows

Comb=[]
for i in range(1, H+W):
    Comb+=combinations(C_comb,i)
    
result=0
for i in range(len(Comb)):
    C_array=np.array(C_list)
    for j in Comb[i]:
        if j[0]=='c':
            c_r=int(j[1:])
            C_array[c_r,:]='r'
        else:
            c_r=int(j[1:])
            C_array[:,c_r]='r'
    df_bool = (C_array=='#')
    result+= df_bool.sum()==K
    
if (np.array(C_list) =='#').sum() ==K:
    result+=1
    
print(result)

Submission status: Accepted

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

for j in range(2**h):
    b1 = ['-']*h
    for k in range(h):
        if ((j>>k)&1):
            b1[h-1-k] = '+'
    for i in range(2**w):
        b2 = ['-']*w
        for k in range(w):
            if ((i>>k)&1):
                b2[w-1-k] = '+'
        val = 0
        for n in range(h):
            for m in range(w):
                if b1[n] == '-' and b2[m] == '-' and a[n][m] == '#':
                    val += 1
        if val == num:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from itertools import combinations as comb
from itertools import chain
import numpy as np

# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter


def solve(H, W, K, C):
    answer = 0
    for hn in range(H + 1):
        for wn in range(W + 1):
            for h_idxs in comb(range(H), hn):
                for w_idxs in comb(range(W), wn):
                    cs = C.copy()
                    cs[h_idxs, :] = 0
                    cs[:, w_idxs] = 0
                    answer += cs.sum() == K
    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    H = int(next(tokens))
    W = int(next(tokens))
    K = int(next(tokens))
    C = np.array(
        [
            list(map(lambda x: {"#": 1, ".": 0}[x], line))
            for line in tokens
        ]
    )
    answer = solve(H, W, K, C)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

def bit(S, j):
    # Sの右からj bit目(0-indexed)
    return (S>>j)&1

ans = 0
for i in range(1<<H):
    for j in range(1<<W):
        cc = copy.deepcopy(c)
        black = 0
        for ki in range(H):
            for kj in range(W):
                if bit(i,ki) == 1:
                    cc[ki] = ["r" for _ in range(W)]
                if bit(j,kj) == 1:
                    for ii in range(H):
                        cc[ii][kj] = "r"

        for ii in range(H):
            for jj in range(W):
                if cc[ii][jj] == "#":
                    black += 1

        if black == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys

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

c = []
for i in range(H):
    c.append(list(map(str, input().split()))[0])

o = 0
p = 0

for i in range(2**H):
    for j in range(2**W):
        o = 0
        for b,n in enumerate(bin(i)[2:].zfill(H)):
            for a,l in enumerate(bin(j)[2:].zfill(W)):
                if n == '0' and l == '0' and c[b][a]=='#':
                    o += 1
        if o == K:
            p += 1
print(p)

Submission status: Accepted

Solution code:
import itertools
a,b,c=map(int, input().split())
l = [input() for i in range(a)]

ans = 0
Ans = 0
for i in itertools.product((1,-1),repeat=a):
    for j in itertools.product((1,-1),repeat=b):
        for k in range(a):
            for m in range(b):
                if i[k] == j[m] == 1 and l[k][m] == '#':
                    ans += 1
        if ans == c:
            Ans += 1
        ans = 0
print(Ans)

Submission status: Accepted

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

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:
#ABC 173 C - H and V
import numpy as np

h,w,k = map(int,input().split())
c = np.zeros((h,w)).astype('str')
for i in range(h):
    s = input()
    for j,a in enumerate(s):
        c[i,j] = a
        
cnt = 0
for o in range(2**h):
    for l in range(2**w):
        black = 0
        for m in range(h):
            for n in range(w):
                if ((o>>m)&1==0) and ((l>>n)&1==0) and (c[m,n]=='#'):
                    black += 1
        if black == k:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def next_line():
    return input()


def next_int():
    return int(input())


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


def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)]


def next_str_array(size):
    return [input() for _ in range(size)]


def main():
    h, w, k = map(int, input().split())
    ch = []
    for _ in range(h):
        ch.append(next_line())

    # print(ch)

    res = 0
    for i in range(1 << h):
        for j in range(1 << w):
            count = 0
            for l in range(h):
                for m in range(w):
                    if ch[l][m] == "#" and (i & (1 << l) == 0) and (j & (1 << m) == 0):
                        count += 1
            if count == k:
                res += 1
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H, W, K = list(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 k in range(H):
            for l in range(W):
                if (i>>k) & 1:
                    if (j>>l) & 1:
                        if c[k][l] == "#":
                           count += 1
        if count == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H,W,K=map(int,readline().split())
C=np.array(list(map(str,read().rstrip().decode().split())))
ans=0
for paint_H in itertools.product([0,1], repeat=H):
  for paint_W in itertools.product([0,1], repeat=W):
    cnt=0
    for i in range(H):
      for j in range(W):
        if paint_H[i]==0 and paint_W[j]==0 and C[i][j]=="#":
          cnt+=1
    if cnt==K:
      ans+=1
print(ans)