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 row in range(1 << H):
  for col in range(1 << W):
    cnt = 0
    for i in range(H):
      for j in range(W):
        if (row & (1 << i)) or (col & (1 << j)):
          continue
        if C[i][j] == '#':
          #print(i, j)
          cnt += 1
    #print("row={}, col={}, cnt={}".format(row, col, cnt))
    if cnt == K:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys

def resolve():
    c = sys.stdin.readlines()
    c = list(map(lambda x: x.strip(), c))
    H, W, K = tuple(map(int, c[0].split(' ')))
    del c[0]
    ans = 0
    for hh in range(1<<H):
        for ww in range(1<<W):
            cnt = 0
            for h in range(H):
                for w in range(W):
                    if hh >> h & 1:
                        continue
                    if ww >> w & 1:
                        continue
                    if c[h][w] == '#':
                        cnt += 1

            if cnt == K:
                ans += 1

    print(ans)

resolve()

Submission status: Accepted

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

for maskR in range(1 << h):
    for maskC in range(1 << w):
        black = 0
        for i in range(h):
            for j in range(w):
                if maskR >> i & 1 == 0 and maskC >> j & 1 == 0 and c[i][j] == '#':
                    black += 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)]
 
h1 = [list(f"{i:0{h}b}") for i in range(2**h)]
w1 = [list(f"{i:0{w}b}") for i in range(2**w)]
 
cnt = 0
for hh in h1:
    for ww in w1:
        black = 0
        x = [i for i in range(h) if hh[i]=='1']
        y = [i for i in range(w) if ww[i]=='1']
        for i in x:
            for j in y:
                if c[i][j] == '#':
                    black += 1
        if black == k:
            cnt += 1
            #print(x, y)
 
print(cnt)

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):
                if row[i] and col[j] and grid[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())
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):
                if row[i] == 0 and col[j] == 0 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())
C = [input().rstrip() for _ in range(H)]

ans = 0

# 0行以上塗りつぶすすべての場合: 2^H通り
# 2進数で考えるとやりやすい
# 例えば、3行ある場合
#   000: 1行も塗らない
#   001: 1行目を塗る
#   010: 2行目を塗る
#   011: 1,2行目を塗る
#   ...
#   111: すべて塗る
# というふうに
for i_bits in range(1 << H):
  
  # 列についても同様の考え方
  for j_bits in range(1 << W):
    
    # すべてのマスについて、黒を数える
    cnt = 0 # 黒の個数
    for i in range(H):
      for j in range(W):
        
        # マスがある行も列も塗られていない場合に
        # 1の左シフトを使っている
        #   1をn個左シフト（1 << n）すると、2進数では1の右に0がn個
        #   1 << 3 = (0b) 1000
        #   これを使う
        # 例：i_bitsが10001のとき、3行目（i=2）は塗られているか？をビットAND演算で調べる
        #     10001
        #   &)00100
        #   -------
        #     00000
        #   結果が0なので塗られていない
        # j_bitsについても同様に確かめる
        if (i_bits & (1 << i)) == 0 and (j_bits & (1 << j)) == 0:
          
          # 黒ならば
          if C[i][j] == "#":
            cnt += 1
            
    if cnt == K:
      ans += 1
      
print(ans)

Submission status: Accepted

Solution code:
# C - H and V


def main():
    H, W, K = map(int, input().split())
    C = [int(input().replace(".", "0").replace("#", "1"), 2) for _ in range(H)]
    res = 0
    for bit in range(1 << (H + W)):
        cnt_black = sum(
            (C[i] >> j) & 1 and not (bit >> i) & 1 and not (bit >> (j + H)) & 1
            for i in range(H)
            for j in range(W)
        )
        if cnt_black == K:
            res += 1
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

h,w,k = (int(x) for x in input().split())
row_cnt = []
col_cnt = []
lst = []
total = 0
for i in xrange(h):
    lst.append([1 if c=='#' else 0 for c in input().strip()])
    row_cnt.append(sum(lst[-1]))
    total += row_cnt[-1]
for j in xrange(w):
    col_cnt.append(sum((lst[i][j] for i in xrange(h))))

ans = 0
for i in xrange(2**h):
    bini = bin(i)[2:]
    bini = ((h-len(bini))*'0')+bini
    curk = total
    for ii,c in enumerate(bini):
        if c == '1':
            curk -= row_cnt[ii]
    
    for j in xrange(2**w):
        binj = bin(j)[2:]
        binj = ((w-len(binj))*'0')+binj
        cur = curk
        for ii,c in enumerate(binj):
            if c == '1':
                bonus = 0
                for jj,cc in enumerate(bini):
                    if cc == '1' and lst[jj][ii] == 1:
                        bonus += 1
                cur -= col_cnt[ii] - bonus
        if cur == 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 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 c[i][j] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
grid = []
for row in range(H):
  grid.append(input())
ans = 0

for i in range(1<<H):
  for j in range(1<<W):
    count = 0
    for row in range(H):
      for col in range(W):
        if (i>>row)&1 == 1 and (j>>col)&1 == 1 and grid[row][col] == '#':
          count += 1
    if count == K: ans += 1
print(ans)

Submission status: Accepted

Solution code:
def li():
    return [int(x) for x in input().split()]

H, W, K = li()
c = [list(input()) for x in range(H)]

ans = 0
for maskRow in range(2**H):
    for maskCol in range(2**W):
        black = 0
        for i in range(H):
            for j in range(W):
                # maskRowのi番目のフラグが立っていない
                # かつ
                # maskColのj番目のフラグが立っていない
                # かつ
                # c[i, j]が#と一致
                if not maskRow & (1 << i) and not maskCol & (1 << j) and c[i][j] == "#":
                    black += 1
        if black == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# C - H and V
def main():
    H, W, K = map(int, input().split())
    C = [input().rstrip() for _ in range(H)]
    res = 0
    for bit in range(1 << (H + W)):
        cnt_black = sum(
            C[i][j] == "#" and not (bit >> i) & 1 and not (bit >> (j + H)) & 1
            for i in range(H)
            for j in range(W)
        )
        if cnt_black == K:
            res += 1
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# C - H and V
def main():
    H, W, K, *C = open(0).read().split()
    H, W, K, C = int(H), int(W), int(K), "".join(C)
    res = 0
    for bit in range(1 << (H + W)):
        cnt_black = sum(
            C[i * W + j] == "#" and not (bit >> i) & 1 and not (bit >> (j + H)) & 1
            for i in range(H)
            for j in range(W)
        )
        if cnt_black == K:
            res += 1
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# C - H and V
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    H, W, K = map(int, readline().split())
    C = [line.decode() for line in readlines()]
    res = 0
    for bit in range(1 << (H + W)):
        cnt_black = sum(
            C[i][j] == "#" and not (bit >> i) & 1 and not (bit >> (j + H)) & 1
            for i in range(H)
            for j in range(W)
        )
        if cnt_black == K:
            res += 1
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# C - H and V
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    H, W, K = map(int, readline().split())
    C = [line.decode() for line in readlines()]
    res = 0
    for bit in range(1 << (H + W)):
        cnt_black = sum(
            not (bit >> i) & 1 and not (bit >> (j + H)) & 1 and C[i][j] == "#"
            for i in range(H)
            for j in range(W)
        )
        if cnt_black == K:
            res += 1
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    H, W, K = map(int, input().split())
    c = [list(input()) for _ in range(H)]
    res = 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:
                res += 1
    print(res)

main()

Submission status: Accepted

Solution code:
# C - H and V
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    H, W, K = map(int, readline().split())
    C = [line.decode() for line in read().split()]
    res = 0
    for bit_row in range(1 << H):
        for bit_col in range(1 << W):
            cnt_black = 0
            for i in range(H):
                for j in range(W):
                    if (
                        not ((bit_row >> i) & 1)
                        and not ((bit_col >> j) & 1)
                        and C[i][j] == "#"
                    ):
                        cnt_black += 1
            if cnt_black == K:
                res += 1
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys 
import numpy as np

readline = sys.stdin.buffer.readline

H, W, K = map(int, readline().split())
# 2次元配列に格納する
C_ij = []
for h in range(H):
    C_ij.append(input()) # bufferだとbがつくのでこちらに

ans = 0
# bit全探索[2重ループver]
for h_bit in range(2**H):
    for w_bit in range(2**W):
        black = 0
        for h in range(H):
            for w in range(W):
                if not((h_bit >> h) & 1) and not((w_bit >> w) & 1) and \
                C_ij[h][w] == '#':
                    black += 1
        if black == K:
            ans += 1

# 配列形式C_ij[H][0][W]
print(ans)

Submission status: Accepted

Solution code:
import copy

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

def tenchi(matrix, H, W):
	tmatrix = []
	for i in range(W):
		tmatrix_row = []
		for vector in matrix:
			tmatrix_row.append(vector[i])
		tmatrix.append(tmatrix_row)    
	return(tmatrix)
for i in range(2**(H+W)):
	tmp = i
	tmpc = copy.deepcopy(c)
	for j in range(H):
		if tmp % 2 == 1:
			tmpc[j] = ["."]*W
		tmp //= 2
	tmpc = tenchi(tmpc, H, W)
	for j in range(W):
		if tmp % 2 == 1:
			tmpc[j] = ['.']*H
		tmp //= 2
	
	count = 0
	for j in range(W):
		for k in range(H):
			if tmpc[j][k]=='#':
				count += 1
	if count == K:
		ans += 1

print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
res = 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:
            res += 1
print(res)

Submission status: Accepted

Solution code:
import copy
H,W,K = map(int,input().split())
ls3 = []
for i in range(H):
    ls1 = input()
    ls2 = [0 if j == '.' else 1 for j in ls1]
    ls3.append(ls2)

ii = 0
for i in range(2**H):
    for j in range(2**W):
        ls4 = copy.deepcopy(ls3)
        for k in range(H):
            for l in range(W):
                if (i>>k & 1):
                    ls4[k][l] = 0
                if (j>>l & 1):
                    ls4[k][l] = 0
        cou = 0
        for ls in ls4:
            cou += ls.count(1)
        if cou == K:
            ii+=1       

print(ii)

Submission status: Accepted

Solution code:
h,w,t = map(int,input().split())
a = []
for _ in range(h):
    b = list(map(str,input()))
    a.append(b)


ans = 0
for i in range(2**h):
    for j in range(2**w):
        cnt = 0
        for k in range(h):
            if ((i>>k)&1):
                for l in range(w):
                    if ((j>>l)&1):
                        if a[k][l] == "#":
                            cnt += 1
        if cnt == t:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# def c():
#     n = int(input())
#     inp = {}
#     for i in range(n):
#         a = input()
#         if inp.get(a) is None:
#             inp[a] = 0
#         inp[a] += 1
#     print(f"AC x {0 if inp.get('AC') is None else inp.get('AC')}")
#     print(f"WA x {0 if inp.get('WA') is None else inp.get('WA')}")
#     print(f"TLE x {0 if inp.get('TLE') is None else inp.get('TLE')}")
#     print(f"RE x {0 if inp.get('RE') is None else inp.get('RE')}")

# c()


h, w, k = [int(x) for x in input().split()]
ans = 0

grid = []

for i in range(h):
    grid.append(list(input()))

black = 0

for maskRow in range(0, 1 << h):
    for maskCol in range(0, 1 << w):
        black = 0
        for i in range(h):
            for j in range(w):
                if (maskRow >> i) & 1 == 0 and (maskCol >> j) & 1 == 0 \
                                                    and grid[i][j] == '#':
                    black += 1
        if black == k:
            ans += 1

print(ans)

Submission status: Accepted

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

counter = 0	
ans = 0
b = 0
for (i,j) in itertools.product(range(h), range(w)):
	if c[i][j] == '#':
		b += 1

for hl in range(h+1):
	for wl in range(w+1):
		for	hi in itertools.combinations(range(h),hl):
			for wj in itertools.combinations(range(w),wl):
				C = copy.deepcopy(c)
				for i in hi:
					for j in range(w):
						if C[i][j] == '#':
							counter += 1
							C[i][j] = '.'
				for j in wj:
					for i in range(h):
						if C[i][j] == '#':
							counter += 1
				if b - counter == k:
					ans += 1
				counter = 0
print(ans)

Submission status: Accepted

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

counter = 0	
ans = 0
b = 0
for (i,j) in itertools.product(range(h), range(w)):
	if c[i][j] == '#':
		b += 1

for hl in range(h+1):
	for wl in range(w+1):
		for	hi in itertools.combinations(range(h),hl):
			for wj in itertools.combinations(range(w),wl):
				C = copy.deepcopy(c)
				for i in hi:
					for j in range(w):
						if C[i][j] == '#':
							counter += 1
							C[i][j] = '.'
				for j in wj:
					for i in range(h):
						if C[i][j] == '#':
							counter += 1
				if b - counter == k:
					ans += 1
				counter = 0
print(ans)

Submission status: Accepted

Solution code:
h,w,k = map(int, input().split())
c = [list(input()) 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 += c[i][j]=="#"
        if cc==k:
            ans += 1
print(ans)

Submission status: Accepted

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

def m_fun(x):
    if x == '.':
        return 0
    return 1

def subsets(s):
    if len(s) == 0:
        return [[]]
    if len(s) == 1:
        return [[], s]
    prev_subsets = subsets(s[1:])
    return prev_subsets + [[s[0]] + l for l in prev_subsets]
    

A = [None] * h
for i in range(h):
    A[i] =  [m_fun(x) for x in list(input())]

count = 0

for ri in subsets(list(range(h))):
    for ci in subsets(list(range(w))):
        subcount = 0
        for i in ri:
            for j in ci:
                if A[i][j] == 1:
                    subcount += 1
        if subcount == k:
            count += 1
            
print(count)

Submission status: Accepted

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

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 == 1 and maskC >> j & 1== 1 and c[i][j]=='#':
                    black += 1


        if black ==k:
            ans += 1

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

ans = 0
for ib in range(1<<H):
    for jb in range(1<<W):
        count = 0
        for i in range(H):
            for j in range(W):
                if ib>>i&1:
                    continue
                if jb>>j&1:
                    continue
                if mat[i][j] == '#':
                    count += 1
        if count == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
h, w, k = map(int, input().split())
ans = 0
s = [input() for _ in range(h)]
for hi in itertools.product([0, 1], repeat=h):
    for wi in itertools.product([0, 1], repeat=w):
        cnt = 0
        for i, j in itertools.product(range(h), range(w)):
            if hi[i] and wi[j]:
                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())
grid = [list(input()) for _ in range(h)]
cnt = 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
                if grid[i][j] == "#":
                    black += 1

        if black == k:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

H, W, K = map(int, input().split())
c = np.array([sum([2 ** i if s == "#" else 0 for i, s in enumerate(input())]) for _ in range(H)])

ans = 0
for h in range(2 ** H):
  h_idx = np.array([bool(h & 2 ** i) for i in range(H)])
  for w in range(2 ** W):
    cnt = 0
    for a in c[h_idx]:
      cnt += bin(a & w).count("1")
    if cnt == K:
      ans += 1
      
print(ans)

Submission status: Accepted

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

c = []
ans = 0

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

for i in range(2**H):
    for j in range(2**W):
        now = 0
        for x in range(H):
            for y in range(W):
                if (i >> x) & 1 and (j >> y) & 1:
                    if c[x][y] == "#":
                        now += 1

        if now == K:
            ans += 1

print (ans)

Submission status: Accepted

Solution code:

def resolve():
    # 想定解：bitを選択しない行列(変化しない)での"#"個数を数える
    H, W, K = map(int, input().split())
    G = [list(input()) for _ in range(H)]

    ans = 0
    for bit_i in range(1<<H):
        for bit_j in range(1 << W):
            cnt = 0
            for i in range(H):
                for j in range(W):
                    if (bit_i>>i & 1) or (bit_j>>j & 1):
                        continue
                    if G[i][j] == "#":
                        cnt += 1
            if cnt == K:
                ans += 1
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import sys
import math
import collections
import heapq

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


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


if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        m, n, k = int_input()

        A = []

        res = 0

        for i in range(m):
            A.append([x for x in input()])

        # print(A)

        for i in range(2 ** m):
            for j in range(2 ** n):
                cnt = 0

                for h in range(m):
                    for w in range(n):
                        if (i>>h & 1): continue
                        if (j>>w & 1): continue
                        cnt += A[h][w] == '#'

                if cnt == k:
                    res += 1

        print(res)

Submission status: Accepted

Solution code:
#bit全探索
#解説AC

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

ans = 0
#1<<n : 2^n
for i in range(1<<H):
    for j in range(1<<W):
      cnt = 0
      for h in range(H):
        for w in range(W):
          #1>>n : 下からn桁目(0 index)
          if (i>>h & 1): continue
          if (j>>w & 1): continue
          cnt += C[h][w] == '#'

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

Submission status: Accepted

Solution code:
import copy

H,W,Q = map(int,input().split())
c = [list(input()) for _ in range(H)]
kotei = copy.deepcopy(c)
ans = 0

K = 2 # 選択肢の数
N = H+W # 問題の個数
for i in range(K**N):
    TF=[0]*N
    c = copy.deepcopy(kotei)

    for j in range(N):
        TF[N-j-1] = i % K
        i //= K
    
    #print(TF)
    for j in range(len(TF)):
        if TF[j] == 1 and 0 <= j < H:
            c[j] = ["R"]*W
        if TF[j] == 1 and j >= H:
            j -= H
            for k in range(H):
                c[k][j] = "R"

    #print(c)
    black = 0
    for j in range(H):
        for k in range(W):
            if c[j][k] == "#":
                black += 1
    if black == Q:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int,input().split())
c_list = [[]]*H

for i in range(H):
    c_list[i] = input()
    c_list[i] = list(c_list[i])

ans = 0
for a in range(2 ** H):
    for b in range(2 ** W):
        black = 0
        for i in range(H):
            for j in range(W):
                if ((a >> i) & 1) and ((b >> j) & 1) and c_list[i][j] == str("#"):
                    black += 1
        if black == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    H, W, K = MI()
    G = np.array([])
    for h in range(H):
        l = LS()
        for i in range(W):
            if l[i] == '#':
                l[i] = 1
            else:
                l[i] = 0
        G = np.append(G, l)
    G = G.reshape((H, W))

    ret = 0
    for x in product((0, 1), repeat=W):
        dX = G * x  # 列方向に 1 or 0 を掛ける
        for y in product((0, 1), repeat=H):
            s = (dX.T * y).sum()
            if s == K:
                ret += 1
    print(ret)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:

def resolve():
    H, W, K = map(int, input().split())
    G = [list(input()) for _ in range(H)]
    all_cnt = sum([g.count("#") for g in G])
    ans = 0
    for bit_i in range(1<<H):
        for bit_j in range(1 << W):
            cnt = 0
            for i in range(H):
                for j in range(W):
                    if bit_i>>i & 1 or bit_j>>j & 1:
                        if G[i][j] == "#":
                            cnt += 1
            if all_cnt - cnt == K:
                ans += 1
    print(ans)

if __name__ == "__main__":
    resolve()

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 and board[i][j]=='#':
          cnt+=1
    if cnt==k:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations
import numpy as np

rm = lambda: map(int, sys.stdin.readline().split())
rr = lambda: sys.stdin.readline().rstrip()

h, w, k = rm()
li = np.array([np.array(list(rr())) for _ in range(h)])
cnt = 0

for i in range(h+1):
    for a in np.array(list(combinations(li, i))):
        a = a.T
        for j in range(w+1):
            for b in np.array(list(combinations(a, j))):
                t = np.count_nonzero(b == '#')
                if t == k:
                    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
#Ci,jを表す配列を作成する
c = []
for i in range(H):
    c.append(input())

ans = 0

# 各行のYes or Noに関して列のYes or Noの全通りを試す
# bit演算を行うことで全通りを簡単に試すことができる
for h in range((1 << H)):
    for w in range((1 << W)):
        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:
def main():
    H, W, K = map(int, input().split())
    B = [[int(c == '#') for c in input()] for _ in range(H)]

    def cnt_bk_cell(mask_r, mask_c):
        """未着色かつ黒のセルを数える"""
        ret = 0
        for r in range(H):
            if (mask_r >> r) & 1: continue  # 着色行は計上対象外
            for c in range(W):
                if (mask_c >> c) & 1: continue  # 着色列は計上対象外
                if B[r][c]: ret += 1
        return ret

    ans = 0
    for mask_r in range(1 << H):  # 2**12
        for mask_c in range(1 << W):
            if K == cnt_bk_cell(mask_r, mask_c): ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
h, w, k = map(int, input().split()) 
s = sys.stdin.readlines()
ans = 0
for ib in range(1<<h):
  for jb in range(1<<w):
    cnt = 0
    for i in range(h):
      if ib >> i & 1:
        continue
      for j in range(w):
        if jb >> j & 1:
          continue
        if s[i][j] == "#":
          cnt += 1
    if cnt == k:
      ans += 1
print (ans)

Submission status: Accepted

Solution code:
import copy

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

bb = 2 ** h
list_i = []
for i in range(bb):
    cc = str(bin(i)[2:]).zfill(h)
    dd = [list(cc)]
    list_i = list_i + dd

bbb = 2 ** w
list_j = []
for i in range(bbb):
    ccc = str(bin(i)[2:]).zfill(w)
    ddd = [list(ccc)]
    list_j = list_j + ddd

for i in range(len(list_i)):
    cij2 = copy.copy(cij)
    for i_ in range(len(list_i[i])):
        if list_i[i][i_]=='1':
            cij2[i_] = ['r' for i in range(w)]
    for j in range(len(list_j)):
        cij3 = copy.deepcopy(cij2)
        for j_ in range(h):
            for j__ in range(len(list_j[j])):
                if list_j[j][j__]=='1':
                    cij3[j_][j__] = 'r'
        cij4 = str(cij3)
        if cij4.count('#') == k:
            Ans = Ans + 1
print(Ans)

Submission status: Accepted

Solution code:
import itertools
h,w,k=map(int,input().split())
li=[]
ans=0
for i in range(h):
    c=input()
    li.append(c)
for n in itertools.product([0,1],repeat=h):
    for m in itertools.product([0,1],repeat=w):
        sharp=0
        for i in range(h):
            if n[i]==1:
                continue
            else:
                for j in range(w):
                    if m[j]==1:
                        continue
                    else:
                        if li[i][j]=="#":
                            sharp+=1
        if sharp==k:
            ans+=1
print(ans)