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:
import numpy as np

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

c = [list(str(input())) for _ in range(h)]
c = np.array(c)
ans = 0

for i in range(2 ** w):  # 横について
    for j in range(2 ** h):  # 縦について
        mas = c.copy()
        for p in range(w):
            for q in range(h):
                if (i >> p) & 1:
                    mas[:, p] = "0"
                if (j >> q) & 1:
                    mas[q, :] = "0"
        # print(mas, "\n", i, j)
        cnt = np.count_nonzero(mas == "#")
        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):
        cnt = 0
        for row in range(H):
            for col in range(W):
                if C[row][col] == '#' and (row_bit[row] == 0 and col_bit[col] == 0):
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()


def main():
    def get_binary(num, digit): return bin(num)[2:].zfill(digit)

    def count_blacks(mat, bin_str_h, bin_str_w):
        count = 0
        for h_i, row in enumerate(mat):
            if (bin_str_h[h_i] == "0"):
                continue
            for w_i, cell in enumerate(row):
                if (bin_str_w[w_i] == "1" and cell == "#"):
                    count += 1

        return count

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

    for h in range(2**H):
        for w in range(2**W):
            h_bin = get_binary(h, H)
            w_bin = get_binary(w, W)
            if (count_blacks(mat, h_bin, w_bin) == K):
                ans_count += 1

    print(ans_count)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


points = 0
for row in range(2**H):
    for col in range(2**W):
        k_pra = 0
        for i in range(H):
            for j in range(W):
                if row&(1<<i)==0 and col&(1<<j)==0 and c[i][j]=='#':
                    k_pra += 1
        if K == k_pra:
            points += 1

print(points)

Submission status: Accepted

Solution code:
def get_binaly_arr(num,digit):
    return list(bin(num)[2:].zfill(digit))

def get_droped_mat(mat,binaly_arr,direction):
    if direction == "H":# 行をdrop!
        return [mat[i] for i in range(len(mat)) if binaly_arr[i] != "0" ]
    elif direction == "W": # 列をdrop!
        return [[arr[i] for i in range(len(arr)) if binaly_arr[i] != "0" ] for arr in mat]
    else :
        print("INVALID DIRECTION!")

def count_black(mat):
    return sum([sum([1 for item in arr if item == "#"]) for arr in mat])
    
if __name__ == "__main__":
    H,W,K = list(map(int,input().split()))
    c = []
    for i in range(0,H):
        c.append(list(input()))

    H_pattern_num = 2 ** H
    W_pattern_num = 2 ** W
    count = 0
    ite_num = 0
    for i in range(0,H_pattern_num):
        for j in range(0,W_pattern_num):
            # バイナリ配列を生成
            H_binaly_arr = get_binaly_arr(i,H)
            W_binaly_arr = get_binaly_arr(j,W)

            mat_temp = c.copy()
            mat_temp = get_droped_mat(c,H_binaly_arr,direction="H")
            mat_temp = get_droped_mat(mat_temp,W_binaly_arr,direction="W")
            if K == count_black(mat_temp):
                count += 1
    print(count)

Submission status: Accepted

Solution code:
import copy

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

ans = 0
for bitrow in range(2**H):
    c1 = copy.deepcopy(matrix)
    for i in range(H):
        if bitrow >> i & 1:
            for column in range(W):#i行目を全て . に置換
                c1[i][column] = '.'
        
    for bitcolumn in range(2**W):
        c2 = copy.deepcopy(c1)
        for j in range(W):
            if bitcolumn >> j & 1:
                for row in range(H):#j列目を全て . に置換
                    c2[row][j] = '.'
                        
        # '#'の数を数える
        black = 0
        for row in c2:
            for st in row:
                if st == '#':
                    black += 1
        
        if black == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

a = input().split()
H = int(a[0])
W = int(a[1])
K = int(a[2])
  
b = []
for i in range(H):
  line = input()
  row = []
  for j in range(W):
    if line[j] == ".":
      row.append(0)    
    elif line[j] == "#":
      row.append(1)
  b.append(row)
b = np.array(b)

r = np.zeros(H)
c = np.zeros(W)

def plus1(x):
  x[0] += 1
  for i in range(len(x)):
    if i < len(x)-1:
      if x[i] == 2:
        x[i] = 0
        x[i+1] += 1
      

count = 0
while r[-1] < 2:
  while c[-1] < 2:
    #print(r, c)
    if K == np.dot(r,(np.dot(b,c))):
      count += 1
    plus1(c)
  c = np.zeros_like(c)
  plus1(r)
    
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
X = []
for i in range(H):
  x = list(input())
  X.append(x)
 
def HandV():
  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:
            if X[i][j]=='#':
              cnt+=1
      if cnt==K:
        ans+=1
  print(ans)
HandV()

Submission status: Accepted

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

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

for i in range(2**H):
    for j in range(2**W):
        count = 0
        for m in range(H):
            for n in range(W):
                if ((i >> m) & 1) and ((j >> n) & 1) and c[m][n] == '#':
                    count = count + 1
        if count == K:
            answer = answer + 1

print(answer)

Submission status: Accepted

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

row=[format(x, '06b') for x in range(2**h)]
column=[format(x, '06b') for x in range(2**w)]

shacnt=0
ans=0

for r in row:
    for c in column:
        shacnt=0
        for gyou in range(1,h+1):
            for retu in range(1,w+1):
                if r[-gyou]=="1" and c[-retu]=="1" and a[gyou-1][retu-1]=="#":
                    shacnt+=1
        if shacnt==k:
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
import copy
[h,w,k] = [int(i) for i in input().split()]
c = []
for i in range(h):
    tmp = input()
    tmp_ls = []
    for j in range(len(tmp)):
        tmp_ls.append(tmp[j])
    c.append(tmp_ls)
cnt = 0
for i in range(2 ** h):
    for j in range(2 ** w):
        tmp = copy.deepcopy(c)
        cnt_b = 0
        bin_h = bin(i)[2:]
        bin_h = "0" * (h - len(bin_h)) + bin_h
        bin_w = bin(j)[2:]
        bin_w = "0" * (w - len(bin_w)) + bin_w
        #print(bin_h,bin_w)
        for p in range(h):
            for q in range(w):
                if bin_h[p]== "1" or bin_w[q] == "1":
                    tmp[p][q] = "."
        #print(tmp)
        for p in range(h):
            for q in range(w):
                if tmp[p][q] == "#":
                    cnt_b += 1
        #print(cnt_b)
        if cnt_b == k:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
import collections
import copy
H,W,K = map(int, input().split())
data_list = [list(input()) for i in range(H)]
data_np = np.array(data_list)
count = 0
for i in range(2 ** H):
  for k in range(2 ** W):
    data_tmp = copy.deepcopy(data_np)
    for j in range(0,H):
      if i >> j & 1:
        data_tmp[j,:] = '.'
    for l in range(0,W):
      if k >> l & 1:
        data_tmp[:,l] = '.'
    if (np.count_nonzero(data_tmp == '#') == K):
      count = count+ 1
print(count)

Submission status: Accepted

Solution code:
from itertools import product

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

def f(i_skip, j_skip):
  cnt = 0
  for i in range(H):
    if i_skip[i] == 1:
      continue
    for j in range(W):
      if j_skip[j] == 1:
        continue
      elif C[i][j] == '#':
        cnt += 1
  return cnt == K

ans = 0
cnt = 0
for i_skip in product(range(2), repeat=H):
  for j_skip in product(range(2), repeat=W):
    ans += int(f(i_skip, j_skip))
print(ans)

Submission status: Accepted

Solution code:
import copy

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

ans = 0
for x in range(2**h):
    for y in range(2**w):
        cnt = 0
        tmp = copy.deepcopy(c)
        for i in range(h):
            if x >> i & 1:
                tmp[i] = ['r']*w
        for j in range(w):
            if y >> j & 1:
                for i in range(h):
                    tmp[i][j] = 'r'
        for i in range(h):
            for j in range(w):
                if tmp[i][j] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
def check(C,p,q,H,W):
    ret = 0
    for i in range(H):
        if p[i] == 1:
            continue
        for j in range(W):
            if q[j] == 1:
                continue
            if C[i][j] == "#":
                ret += 1
    return ret

def main():
    H, W, K = map( int, input().split())
    C = [ list( input()) for _ in range(H)]
    ans = 0
    for p in product(range(2), repeat=H):
        for q in product(range(2), repeat=W):
            if check(C,p,q,H,W) == K:
                ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

def HandV():
  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:
            if X[i][j]=='#':
              cnt+=1
      if cnt==K:
        ans+=1
  print(ans)
HandV()

Submission status: Accepted

Solution code:
h,w,k = map(int,input().split())
mat = []
for i in range(h):
	mat.append(list(input()))
cnt = 0
for row in range((1 << h) - 1):
	for col in range((1 << w) - 1):
		black = 0
		for i in range(h):
			for j in range(w):
				if ((row >> i) & 1 == 0) and ((col >> j) & 1 ==0):
					if mat[i][j] == "#":
						black+=1 
		if black == 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)]

count = 0

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

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()

h, w, k = [int(x) for x in input().split()]
g = [input() for _ in range(h)]
ans = 0
for r in range(1 << h):
    for c in range(1 << w):
        if sum(1 for i in range(h) for j in range(w) if (r & (1 << i)) == 0 and (c & (1 << j)) and g[i][j] == '#') == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
import numpy as np

H, W, K = [int(n) for n in input().split()]
arr = np.zeros((H, W))
count = 0

for h in range(H):
    row = input()
    arr[h, :] = np.array([0 if mark=='.' else 1 for mark in row])

for row_onehot, col_onehot in product(product(range(2), repeat=H), product(range(2), repeat=W)):
    row_indexes = np.argwhere(np.array(row_onehot)==1).flatten()
    col_indexes = np.argwhere(np.array(col_onehot)==1).flatten()
    arr_ = arr.copy()
    for row_idx in row_indexes:
        arr_[row_idx, :] = 0
    for col_idx in col_indexes:
        arr_[:, col_idx] = 0
    if arr_.sum() == K:
        count += 1

print(count)

Submission status: Accepted

Solution code:
import copy
H,W,K = list(map(int,input().rstrip().split(' ')))
MASU = [list(input()) for _ in range(H)]
H2_li = []
W2_li = []
C_black = 0
for i in range(2**H):
    H2 = []
    for j in range(H):
        if ((i>>j)&1):H2.append(1)
        else:H2.append(0)
    H2_li.append(H2)
for i in range(2**W):
    W2 = []
    for j in range(W):
        if ((i>>j)&1):W2.append(1)
        else:W2.append(0)
    W2_li.append(W2)

for h2 in H2_li:
    for w2 in W2_li:
        masu = copy.deepcopy(MASU)
        for i,h in enumerate(h2):
            if h == 1:
                masu[i] = ['r']*W
        for i,w in enumerate(w2):
            if w == 1:
                for k in range(H):
                    masu[k][i] = 'r'
        count = 0
        for h in range(H):
            for w in range(W):
                if masu[h][w]=='#':count+=1
        if count == K:C_black+=1

print(C_black)

Submission status: Accepted

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

ans = 0
for rbit in range(1 << h):
    for cbit in range(1 << w):
        black = 0
        for i in range(h):
            for j in range(w):
                if (rbit >> i) & 1 == 0 and (cbit >> j) & 1 == 0 and table[i][j] == '#':
                    black += 1
        if black == k:
            ans += 1
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
matrix = [list(input()) for i in range(h)]
ans = 0
for paint_h in range(1 << h):
    for paint_w in range(1 << 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 matrix[i][j] == "#":
                        cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
grid = [input() for _ in range(h)]
n = h + w 
ans = 0
for bit in range(1<<n):
    cnt = 0
    for i in range(h):
        for j in range(w):
            if (bit >> i) & 1 :
                if (bit >> h + j) & 1:
                    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 = [list(input()) for _ in range(h)]
black = 0
ans = 0

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
from operator import itemgetter
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
H,W,K = LI()
C = []
ans = 0

for l in [S() for _ in range(H)]:
	C.append(list(l))

for i in range(2**(H+W)):
	c = copy.deepcopy(C)
	sum = 0
	for j in range(H+W):
		if ((i>>j)&1):
			if j < H:
				for d in range(W):
					c[j][d] = '.'
			else:
				for d in range(H):
					c[d][j-H] = '.'
	for l in c:
		for w in l:
			if w == '#':
				sum += 1
	if sum == K:
		ans += 1
print(ans)

Submission status: Accepted

Solution code:
import copy as cp
import itertools as itr
import numpy as np

H,W,K=map(int, input().split())
c=np.array([list(input()) for l in range(H)])
cnt=0

cnt=np.count_nonzero(c == '#')

hi=list(itr.product(range(2),repeat=H))
vi=list(itr.product(range(2),repeat=W))

ans=0

for i in range(len(hi)):
  for j in range(len(vi)):
    c1=cp.deepcopy(c)
    for i1 in range(H):
      if hi[i][i1]==1:
        c1[i1]='x'      
    for j1 in range(W):
      if vi[j][j1]==1:
        c1[:,j1]='x'
    cnt2=np.count_nonzero(c1 == '#')
    if cnt2==K:
      ans+=1
          
      
      

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
# print(c)
black = 0
ans = 0

for bit_h in range(2**h):
    for bit_w in range(2**w):
        black = 0
        for i in range(h):
            for j in range(w):
                if ((bit_h >> i) & 1) and ((bit_w >> j) & 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())
c=[list(input()) for _ in range(h)]

from itertools import product
h_bits=list(product([0,1], repeat=h))
w_bits=list(product([0,1], repeat=w))

ans=0
for h_bit in h_bits:
    for w_bit in w_bits:
        tmp_cnt=0
        for i, h_b in enumerate(h_bit):
            for j, w_b in enumerate(w_bit):
                if h_b==0 and w_b==0 and c[i][j]=="#":
                    tmp_cnt+=1
        if tmp_cnt==k:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
# print(c)
black = 0
ans = 0

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

Submission status: Accepted

Solution code:
# coding:utf-8

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
# print(c)
black = 0
H = []
W = []
ans = 0

for bit_h in range(2**h):
    for bit_w in range(2**w):
        black = 0
        for i in range(h):
            if ((bit_h >> i) & 1) == 1:
                continue
            for j in range(w):
                if ((bit_w >> 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())
c_ij = []
for i in range(H):
    c_ij.append(list(input()))


ans = 0

for i in range(2**H):
    for j in range(2**W):
        c = copy.deepcopy(c_ij)
        for ii in range(H):
            if ((i>>ii) & 1):
                for jj in range(W):
                    c[ii][jj] = "."

        for jj in range(W):
            if ((j>>jj) & 1):
                for ii in range(H):
                    c[ii][jj] = "."


        memo = 0
        for ii in range(H):
            for jj in range(W):
                if c[ii][jj] == "#":
                    memo+= 1

        if memo == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
c=[list(input()) for _ in range(h)]
from itertools import combinations as co
g=[[-1]]
for i in range(1,h+1):
  g+=co(range(h),i)
r=[[-1]]
for i in range(1,w+1):
  r+=co(range(w),i)
ans=0
for gl in g:
  for rl in r:
    t=0
    for i in range(h):
      if i not in gl:
        for j in range(w):
          if j not in rl:
            t+=(c[i][j]=='#')
    ans+=(t==k)
print(ans)

Submission status: Accepted

Solution code:
#ビット全探索の例

H, W, K = map(int, input().split())
C = []
for _ in range(H): C.append([c for c in input()])
ans = 0
for i in range(1<<H):
   for j in range(1<<W):
       cnt = 0
       for m in range(H):
           for n in range(W):
               if i>>m&1: continue
               if j>>n&1: continue
               if C[m][n] == '#': cnt += 1
       if cnt == K: ans += 1
print(ans)

Submission status: Accepted

Solution code:
# ビット演算でなく, itertoolsモジュールのproductとrange(2)の組み合わせを活用.
# ※を！

from itertools import product

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

ans = 0

#l = list(product(range(2), repeat=h))
#m = list(product(range(2), repeat=w))
#print(l)
#print(m)

for row_bit in product(range(2), repeat=h):# ※長さがhで, 要素が'1'か'0'であるすべての組み合わせをすべて列挙
    for col_bit in product(range(2), repeat=w): # ※ここでは'1'(True)が塗られていない状態
        cnt = 0
        for row in range(h):
            for col in range(w):
                #print(row_bit[row] and col_bit[col])
                if c[row][col] == "#" and (row_bit[row] and col_bit[col]):#()は赤で塗られていない確認→縦も横も'1'(True)であることの確認
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
h,w,k=map(int,input().split())
masu=[]
ans=0
for i in range(h):
  slist=list(map(str,input()))
  masu.append(slist)
for i in range(2**h):
  for j in range(2**w):
    black=0
    for m in range(h):
      for n in range(w):
        if ((i >> m) & 1) and ((j >> n)&1) and masu[m][n]=='#':
          black+=1
    if black==k:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
# ビット演算でなく, itertoolsモジュールのproductとrange(2)の組み合わせを活用.
# ※を！

from itertools import product

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

ans = 0

#l = list(product(range(2), repeat=h))
#m = list(product(range(2), repeat=w))
#print(l)
#print(m)

for row_bit in product(range(2), repeat=h):# ※長さがhで, 要素が'1'か'0'であるすべての組み合わせをすべて列挙
    for col_bit in product(range(2), repeat=w):
        cnt = 0
        for row in range(h):
            for col in range(w):
                if row_bit[row] == 0 and col_bit[col] == 0:# 縦横赤で塗られることなく...
                    if c[row][col] == "#": #もともと黒で塗られている場合
                        cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# ビット演算でなく, itertoolsモジュールのproductとrange(2)の組み合わせを活用.
# ※を！

from itertools import product

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

ans = 0

#l = list(product(range(2), repeat=h))
#m = list(product(range(2), repeat=w))
#print(l)
#print(m)

for row_bit in product(range(2), repeat=h):# ※長さがhで, 要素が'1'か'0'であるすべての組み合わせをすべて列挙
    for col_bit in product(range(2), repeat=w):
        cnt = 0
        for row in range(h):
            for col in range(w):
                #print(row_bit[row] and col_bit[col])
                if c[row][col] == "#" and (row_bit[row] and col_bit[col]):# ここのブール演算！
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
import numpy as np

h, w, k = rl()
a=[list(rs()) for _ in range(h)]
ans=0
for i in range(1<<h+w):
    c = np.array(a[:])
    for n in range(h+w):
        if i>>n&1:
            if n>=h:
                c[:,n-h-1]="*"
            else:
                c[n-1,:]="*"
    cnt=0
    for y in range(h):
        for x in range(w):
            if c[y][x]=="#":
                cnt+=1
    if cnt==k:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import product
 
h, w, k = map(int, input().split())
grid = np.array([list(map(str, input().rstrip())) for _ in range(h)])
 
ans = 0
for i in np.array(list(product([0, 1], repeat=h)), dtype=np.bool):
    for j in np.array(list(product([0, 1], repeat=w)), dtype=np.bool):
        if np.any(i) and np.any(j):
            arr = grid[i].copy()
            arr = arr[:, j]
            arr = arr.flatten()
            if np.where(arr == "#")[0].shape[0] == k:
                ans += 1
 
print(ans)

Submission status: Accepted

Solution code:
from copy import deepcopy
h, w, k = map(int, input().split())
c = []
for i in range(h):
    c.append(list(input()))
ans = 0
for mask_row in range(2 ** h):
    for mask_col in range(2 ** w):
        c_copy = deepcopy(c)
        for row in range(h):
            if mask_row & (1 << row):
                for col in range(w):
                    c_copy[row][col] = '.'
        for col in range(w):
            if mask_col & (1 << col):
                for row in range(h):
                    c_copy[row][col] = '.'
        black = 0
        for row in range(h):
            for col in range(w):
                if c_copy[row][col] == '#':
                    black += 1
        if black == k:
            ans += 1
print(ans)

Submission status: Accepted

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

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:
          continue
        if (w >> 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())
C = [[]*W]*H
for i in range(H):
  C[i] = list(str(input()))
#print(C)
ans = 0
for maskh in range((1<<H)-1):
  for maskw in range((1<<W)-1):
    black = 0
    for i in range(H):
      for j in range(W):
        #print(i,j,C)
        if (maskh >> i) & 1 == 0 and (maskw >> 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 = [input() for _ in range(H)]

ans = 0
for i in range(1 << H+W):
    hcnt = []
    wcnt = []
    cnt = 0
    for j in range(H+W):
        if (i >> j) % 2 == 0:
            continue
        if j < H:
            hcnt.append(j)
        else:
            wcnt.append(j-H)
    for j in hcnt:
        for k in wcnt:
            if c[j][k] == "#":
                cnt += 1
    
    if cnt == K:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools
import numpy as np

N, W, K = map(int, input().split())
g_all = np.array([list(input()) for i in range(N)])

K_all = np.count_nonzero(g_all == '#')
count = 0

def dfs(i, g):
    if (i < N):
        g[i, :] = ['r'] * W
    else:
        g[:, i - N] = ['r'] * N
    return g

g = g_all

for L in range(2 ** (N + W)):
    g = g_all.copy()
    for i in range(N + W):
        if (i < N):
            if ((L >> i) & 1):
                g[i, :] = ['r'] * W
        else:
            if ((L >> i) & 1):
                g[:, i - N] = ['r'] * N
    if np.count_nonzero(g == '#') == K:
        count += 1
print(count)

Submission status: Accepted

Solution code:
import numpy as np
H, W, K = [int(x) for x in input().split(" ")]
C = np.array([
  [True if x == "#" else False for x in input()]
  for _ in range(H)
], dtype=bool)

count = 0
for i in range(2**(H + W)):
    indicator = [i & 2**j != 0 for j in range(H + W)]
    Cc = C.copy()
    Cc[indicator[:H], :] = False
    Cc[:, indicator[H:]] = False
    if np.sum(Cc) == K:
        count += 1
print(count)

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 i2 in range(h):
            for j2 in range(w):
                if c[i2][j2]=='#' and i>>i2&1==0 and j>>j2&1==0:
                    black +=1
        if black == k:
            ans+=1
print(ans)

Submission status: Accepted

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

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:
                    continue
                if (w >> j) & 1:
                    continue
                if x[i][j] == '#':#1つ1つマスが黒か見ていくが、そのマスが含まれている行と列が消えていない場合にのみ行う
                    cnt +=1
        if K== cnt:
            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
sou=0
for i in range(h):
  for j in range(w):
    if c[i][j]=="#":
      sou+=1
for i in range(2**h):
  count=0
  ss=set()
  for j in range(h):
    if (i >> j)&1:
      for l in range(w):
        if c[j][l]=="#":
          count+=1
          ss.add((j,l))
  for i2 in range(2**w):
    count2=0
    for j in range(w):
      if (i2 >> j)&1:
        for l in range(h):
          if c[l][j]=="#" and not((l,j) in ss):
            count2+=1
    if sou-(count+count2)==k:
      ans+=1
print(ans)

Submission status: Accepted

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

li = [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):#Heightと同じ回数判定する。
            for j in range(W):
                if (h>>i)&1==0 and (w>>j)&1==0:
                    if li[i][j] == '#':
                        c +=1
        if c==K:
            ans+=1
print(ans)