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, n = map(int, input().split())
test = [input() for i in range(h)]
ans = 0
for binh in range(2 ** h):
	for binw in range(2 ** w):
		tmp = 0
		for l in range(h):
			for m in range(w):
				if ((binh >> l) & 1) == 0  and ((binw >> m) & 1) == 0 and test[l][m] == "#":
					tmp += 1
		if tmp == n:
			ans += 1	
print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8

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

HB = [0] * H 
ans = 0

for i in range(H):
    koko = input()
    HB[i] = koko

for r in range(int(1 << H) - 1):
    for c in range(int(1 << W) - 1):
        black = 0
        for i in range(H):
            for j in range(W):
                if((r >> i) & 1) == 0 and ((c >> j) & 1) == 0 and HB[i][j] == '#':
                    black += 1
        if black == K:
            ans += 1

print('{}'.format(ans))

Submission status: Accepted

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

# from math import gcd
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

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

def calc(lis):
    global C, K

    c = copy.copy(C)

    for i in lis:
        if i // 10 == 1:
            c[i%10-1] = "-" * W
        else:
            for j in range(H):
                tmp = list(c[j])
                tmp[i-1] = "-"
                c[j] = "".join(tmp)

    ct = 0
    for i in c:
        a = Counter(i)
        ct += a["#"]
    
    if ct == K:
        return 1
    return 0
                
count = 0
lis = list(range(1, W + 1)) + list(range(11, 10 + H + 1))

ret = 0
for i in range(H+W):
    for com in list(combinations(lis, i)):
        ret += calc(com)

print(ret)

Submission status: Accepted

Solution code:
import itertools
import copy

h,w,k = list(map(int, input().split()))
lst = [None for i in range(h)]
for i in range(h):
    lst[i] = list(input())
ans = 0

H = list(itertools.product([0,1],repeat=h))
W = list(itertools.product([0,1],repeat=w))

for i in H:
    for j in W:
        lst_test = copy.deepcopy(lst)
        for I in range(h):
            if i[I]==1:
                for a in range(w):
                    lst_test[I][a] = "R"
        for J in range(w):
            if j[J]==1:
                for a in lst_test:
                    a[J] = "R"
        # print(i,j)
        # print(lst_test)
        count = 0
        for a in lst_test:
            for b in a:
                if b=="#":
                    count += 1
        if count == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
def get_unique_list(seq):
  seen = []
  return [x for x in seq if x not in seen and not seen.append(x)]

import itertools
h,w,k = map(int, input().split())
m = []
s=0
for i in range(h):
  t = input()
  m.append(t)
  s+=t.count("#")
list_w = [i for i in range(w)]
list_h = [i for i in range(h)]
combi_w=[]
combi_h=[]
for i in range(w):
  for pair in itertools.combinations(list_w, i):
    combi_w.append(pair)
for i in range(h):
  for pair in itertools.combinations(list_h, i):
    combi_h.append(pair)
ans=0
for i in combi_w:
  temp_w=[]
  for row in i:
    for c in range(h):
      if m[c][row] == "#":
        temp_w.append([c,row])
  for j in combi_h:
    temp_h=[]
    for col in j:
      for r in range(w):
        if m[col][r] == "#":
          temp_h.append([col,r])
    temp2 = get_unique_list(temp_w + temp_h)
    if len(temp2) == s-k:
      ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

H, W, K = map(int, input().split())
m = []
for _ in range(H):
  m.append([1 if s=="#" else 0 for s in input()])

m = np.array(m)
ans = 0

for h in range(2**H):
  for w in range(2**W):
    mcopy = m.copy()
    hcopy = h
    wcopy = w
    for i in range(H):
      if hcopy%2==1:
        mcopy[i,:] = 0
      hcopy = hcopy//2
    for i in range(W):
      if wcopy%2==1:
        mcopy[:,i] = 0
      wcopy = wcopy//2
    if mcopy.sum()==K:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
def count(lst):
    count = 0
    for i in lst:
        for j in i:
            if j == "#": count += 1
    return count

def main(n, m, k, lst):
    ways = 0
    for i in range(2**(n+m)):
        binS = "0" * ((n+m) - len(str(bin(i))[2:])) + str(bin(i))[2:]
        lst1 = lst.copy()
        ind, ind1 = 0, 0
        for j in range(len(binS)):
            if binS[j] == "1":
                if j+1 <= m:
                    for r in range(len(lst1)):
                        lst1[r] = lst1[r][:j-ind] + lst1[r][j+1-ind:]
                    ind += 1
                else:
                    c = j - m - ind1
                    lst1 = lst1[:c] + lst1[c+1:]
                    ind1 += 1
        if count(lst1) == k:
            ways += 1
    return ways

lst = []
n, m, k = [int(x) for x in input().split()]
for _ in range(n):
    s = input()
    lst.append(s)
print(main(n, m, k, lst))

Submission status: Accepted

Solution code:
h,w,z = map(int,input().split())
import copy
c = [list(input()) for _ in range(h)]
ans = 0
for i in range(2**h):
    for j in range(2**w):
        mat = copy.deepcopy(c)
        count = 0
        for k in range(w):
            if j>>k &1:
                for u in range(h):
                    mat[u][k] = "red"
        for l in range(h):
            if i>>l & 1:
                for g in range(w):
                    mat[l][g] = "red"
        for k in range(h):
            for l in range(w):
                if mat[k][l] == "#":
                    count += 1
        if count == z:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import chain, combinations, product

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

def create_grid(rows, value_map, dtype=None):
    return np.array([[value_map[c] for c in row] for row in rows], dtype=dtype)
grid = create_grid(rows, {'.': 0, '#': 1})

count = 0
row_combinations = list(chain(*[combinations(range(H), i) for i in range(H)]))
column_combinations = list(chain(*[combinations(range(W), i) for i in range(W)]))
for rows, columns in product(row_combinations, column_combinations):
    copy = grid.copy()
    for i in rows:
        copy[i] = 0
    for j in columns:
        copy[:, j] = 0
    if copy.sum() == K:
        count += 1

print(count)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
'''
全通り列挙して数える
'''

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

c = []
cnt = 0
ans = 0

for i in range(h):
    c.append(str(input()))

for i in range(2**h):
    for j in range(2**w):
        cnt = 0
        for ib in range(h):
            for jb in range(w):
                #h,wどっちかフラグ経ったら無視する
                if (i>>ib)&1 or (j>>jb)&1:
                    pass
                elif c[ib][jb] == "#":
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
L=list()
for i in range(h):
    L.append(list(input()))
import itertools
import copy
v1=itertools.product([0,1],repeat=h)
v2=itertools.product([0,1],repeat=w)
V=list(itertools.product(v1,v2))
ans=0
for v in V:
    #print(v)
    #print(v[0][0])
    S=0
    Lcopy=copy.deepcopy(L)
    #print(Lcopy)
    for i in v[0]:
        for j in range(h):
            if v[0][j]==1:
                Lcopy[j]=['.']*w
    for i in v[1]:
        for j in range(w):
            if v[1][j]==1:
                for l in range(h):
                    Lcopy[l][j]='.'
    #print(Lcopy)
    for i in range(h):
        for j in range(w):
            if Lcopy[i][j]=='#':
                S+=1
    if S==k:
        ans+=1
        #print(Lcopy)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

def solve():
    import numpy as np
    import copy

    H, W, K = list(map(int, input().split()))
    Cs = []
    for _ in range(H):
        s = input()
        lst = []
        for moji in s:
            a = 0 if moji == "." else 1
            lst.append(a)
        Cs.append(lst)
    Cs = np.array(Cs)

    Hs = []
    for bits in range(1<<H):
        lst = []
        for i in range(H):
            lst.append(bits>>i&1)
        Hs.append(np.array(lst).reshape(H,1))

    Ws = []
    for bits in range(1<<W):
        lst = []
        for i in range(W):
            lst.append(bits>>i&1)
        Ws.append(np.array(lst))

    ans = 0
    oCs = Cs
    for hs in Hs:
        for ws in Ws:
            Cs = copy.deepcopy(oCs)
            # print(Cs)
            Cs *= ws
            Cs *= hs
            # print(ws)
            # print(hs)
            # print(Cs)
            # input()
            if Cs.sum() == 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 l in range(h):
            for m in range(w):
                if (i >> l) & 1 == 0 and (j >> m) & 1 == 0: #塗りつぶされていなければTrue
                    if c[l][m] == "#": #Trueかつ'#'であればカウント
                        cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

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

Map = []
M = []
for _ in range(H):
    M.append(input())
Map = [list(i) for i in M]
tmpH = [2**h for h in range(H)]
tmpW = [2**w for w in range(W)]

#print(Map)
########################

numH = 2**H
numW = 2**W
count = 0
result = 0

for nh in range(numH):
    for nw in range(numW):
        for h_id in range(len(tmpH)):
            for w_id in range(len(tmpW)):
                if tmpH[h_id] & nh == 0 and tmpW[w_id] & nw == 0 and Map[h_id][w_id] == '#':
                    count += 1
        if count == K:
            result += 1
        count = 0

print(result)

Submission status: Accepted

Solution code:
h, w, k = [int(s) for s in input().split() ]
squares = []
# . : 白
# # : 黒
for i in range(h):
    squares = squares + [s for s in input()]

ans = 0
for i in range(2**h):
    for j in range(2**w):
        buf = [s for s in squares]
        for d in range(h):
            if (i>>d) & 1:
                for n in range(w):
                    buf[d * w + n] = 'x'

        for d in range(w):
            if (j>>d) & 1:
                for n in range(h):
                    buf[d + w * n] = 'x'

        if buf.count('#') == k:
            ans = ans + 1

print(ans)

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
import numpy as np
import copy
H, W, K = map(int, input().split())
mat = np.zeros((H, W), dtype = int)
for i in range(H):
    s = input()
    s = s.replace('.', '0 ')
    s = s.replace('#', '1 ')
    mat[i, :] = list(map(int, s.split()))
cnt = 0
for i in range(2 ** H):
    for j in range(2 ** W):
        a = copy.deepcopy(mat)
        for k in range(H):
            if (i >> k) & 1:
                a[k, :] *= 0
            for l in range(W):
                if (j >> l) & 1:
                    a[:, l] *= 0
        if np.count_nonzero(a == 1) == K:
            cnt += 1
print(cnt)

Submission status: Accepted

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

id_count = 0
d = {}

for i in range(H):
  
  l = input()
  for j in range(W):
#    print(i,j,j+H)
    if l[j] == '#':
      if i in d:
        d[i].append(id_count)
      else:
        d[i]=[id_count]
        
      if j+H in d:
        d[j+H].append(id_count)
      else:
        d[j+H]=[id_count]
      id_count +=1

#print(d)
      
ans = 0
#print(id_count)

#if id_count == K:
#  print(1)
#else:
  
for i in range(2 ** (H+W)):
  wrk_list=[]
  for j in range(H+W):  # このループが一番のポイント
    if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
      wrk_list.extend(d.get(j,[]))  
    if wrk_list==[]:
      set1 = []
    else:
      set1 = set(wrk_list)
  
#    print('set',set1,i)
  if id_count - len(set1) == 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 h_p in range(2 ** h):
    for w_p in range(2 ** w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if (h_p >> i) & 1 and (w_p >> j) & 1 and c[i][j] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import copy
import numpy as np


def count_black(c):
    count = 0
    for row in c:
        count += row.count('#')
    return count


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

for h_p in range(2 ** h):
    for w_p in range(2 ** w):
        c_cp = np.array(copy.deepcopy(c))
        for i in range(h):
            if (h_p >> i) & 1:
                c_cp[i, :] = 'r'

        for j in range(w):
            if (w_p >> j) & 1:
                c_cp[:, j] = 'r'

        if count_black(c_cp.tolist()) == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np


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

    ans = 0
    for paint_h in range(2 ** h):
        for paint_w in range(2 ** w):
            cnt = 0
            for j in range(h):
                for l in range(w):
                    if ((paint_h >> j) & 1) == 0 and ((paint_w >> l) & 1) == 0:
                        if cs[j][l] == '#':
                            cnt += 1
            if cnt == k:
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
from copy import copy

def binaryList(n,HW):
    l=np.zeros(HW)
    for i in range(HW):
        if n%2==0:
            l[i]=0
        else:
            l[i]=1
        n=n//2
    return l

if __name__ == "__main__":
    HWK=input().split(" ")
    H,W,K=int(HWK[0]),int(HWK[1]),int(HWK[2])
    l=[]
    for i in range(H):
        buf=[]
        s=input()
        for i in s:
            buf.append(1 if i=="#" else 0)
        l.append(buf)
    l=np.array(l,np.uint8)
    cnt=0
    for i in range(2**H):
        for j in range(2**W):
            buf=copy(l)
            h=binaryList(i,H).reshape(1,-1).repeat(W,0).transpose().astype(np.uint8)
            w=binaryList(j,W).reshape(1,-1).repeat(H,0).astype(np.uint8)
            buf[h==1]=0
            buf[w==1]=0
            if buf.sum()==K:
                cnt+=1
    print(cnt)

Submission status: Accepted

Solution code:
import copy
h,w,k = map(int,input().split())
c = [[1*(i=="#") for i in list(input())] for j in range(h)]
ans = 0
for i in range(2**h):
    l1 = []
    for i1 in range(h):
        l1.append(i >> i1 & 1)
    for j in range(2**w):
        l2 = []
        for j1 in range(w):
            l2.append(j >> j1 & 1)
        
        c2 = copy.deepcopy(c)
        for i2 in range(h):
            if l1[i2]:
                for j3 in range(w):
                    c2[i2][j3] = 0
        for j2 in range(w):
            if l2[j2]:
                for i3 in range(h):
                    c2[i3][j2] = 0
        s = 0
        for t in range(h):
            s += sum(c2[t])
        if s == k:
            ans += 1

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(2 ** h):
    hst = set()
    for ii in range(h):
        if (i >> ii) & 1:
            hst.add(ii)
    for j in range(2 ** w):
        wst = set()
        for jj in range(w):
            if (j >> jj) & 1:
                wst.add(jj)
        cnt = 0
        for x in range(h):
            for y in range(w):
                if x in hst or y in wst:
                    continue
                if c[x][y] == "#":
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    H, W, K = [int(i) for i in input().split(' ')]
    grid = [list(input()) for i in range(H)]
    res = 0
    for i in range(2**H):
        for j in range(2**W):
            g = grid

            remains_black = 0
            for h in range(H):
                if (i >> h) & 1 == 1:
                    continue
                for w in range(W):
                    if (j >> w) & 1 == 1:
                        continue
                    if grid[h][w] == '#':
                        remains_black += 1

            if remains_black == K:
                res += 1
    return res

if __name__ == '__main__':
   print(main())

Submission status: Accepted

Solution code:
from itertools import product

H, W, K = map(int, input().split())
ary = []
for y in range(H):
    ary.append(input())

case = 0
for yb in range(1<<H):
    for xb in range(1<<W):
        nb = 0
        for y in range(H):
            for x in range(W):
                if ((not ((yb >> y) & 1) and ((xb >> x) & 1))) and ary[y][x] == '#':
                    nb += 1
        if nb == K:
            case += 1

print(case)

Submission status: Accepted

Solution code:
def resolve():
    H, W, K = map(int, input().split())
    c = []
    ans = 0
    for i in range(H):
        C = list(input())
        c.append(C)
    for p in range(2**H):
        for q in range(2**W):
            count = 0
            for h in range(H):
                for j in range(W):
                    if ((p >> h) & 1) == 0 and ((q >> j) & 1) == 0 and c[h][j] == "#":
                        count += 1
            if count == K:
                ans += 1
    print(ans)
resolve()

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split(' '))
C = []*H
ans=0
C = [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 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=[list(input()) for _ in range(H)]
ans=0

for i in range(2**(H+W)):
    H_,W_=[0]*H,[0]*W
    bin_=format(i,'b').zfill(H+W)
    for n,b in enumerate(bin_):
        if n<H and b=='1':
            H_[n-1]=1
        elif n>=H and b=='1':
            W_[n-H]=1
    blackCnt=0
    for n,c_ in enumerate(C):
        for m,c in enumerate(c_):
            if H_[n]==0 or W_[m]==0:
                continue
            if c=='#':
                blackCnt+=1
    if blackCnt==K:
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
h, w, k = [int(x) for x in input().rstrip().split(' ')]
counter = 0
mat = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
  line = input().rstrip()
  for j, c in enumerate(line):
    if c == '#':
      mat[i][j] = 1
h_mask = [0 for i in range(h)]
w_mask = [0 for j in range(w)]
for itr in range(2**(h+w)):
  _counter = 0
  for i in range(h):
    h_mask[i] = itr%2
    itr//=2
  for j in range(w):
    w_mask[j] = itr%2
    itr//=2
  for i in range(h):
    for j in range(w):
      if h_mask[i] == 1 and w_mask[j] == 1:
        _counter += mat[i][j]
  if _counter == k:
    counter+=1

print(counter)

Submission status: Accepted

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

import numpy as np

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

c = np.zeros((H, W))
result = 0
for i in range(H):
    word = input()
    for j in range(W):
        if word[j] == '.':
            c[i][j] = 0
        elif word[j] == '#':
            c[i][j] = 1

for mask_h in range(2**H):
    bin_mask_h = format(mask_h,  '0' + str(H) + 'b')
    for mask_w in range(2**W):
        bin_mask_w = format(mask_w, '0' + str(W) + 'b')
        black_num = 0
        for i in range(H):
            if bin_mask_h[i] == '0':
                continue
            for j in range(W):
                if bin_mask_w[j] == '0':
                    continue
                if c[i][j] == 1:
                    black_num += 1
        # print(str(bin_mask_h) + ' ' + str(bin_mask_w) + ' ' + str(black_num))
        if black_num == K:
            result += 1

print(result)

Submission status: Accepted

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

for x in range(2**h):
    for y in range(2**w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if (x&(1<<i)) or (y&(1<<j)):
                    continue
                if c[i][j] == "#":
                    cnt += 1

        if cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import itertools
H,W,K = map(int,input().split())
all_,choice = [],[]

lis = ['h'+str(h) for h in range(H)]
w_lis = ['w'+str(w) for w in range(W)]
lis.extend(w_lis)

for j in range(0,len(lis)+1):
  choice.extend(list(itertools.combinations(lis,j)))

for h in range(H):
  l = list(input().replace('#','1').replace('.','0'))
  all_.append(l)

all_ = np.array(all_,dtype=int)
ans = 0

for i in choice:
  A = all_.copy()
  for k in i:
    if k==None:
      pass
    elif k[0]=='h':
      A[int(k[1]),:]=0
    elif k[0]=='w':
      A[:,int(k[1])]=0
  #print(A)
  if A.sum()==int(K):
    ans+=1
      
print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
board = [input() for _ in range(h)]
cnt = 0
for redlines in range(2**h):
    redlines_bin = format(redlines, 'b').zfill(h)
    for redclms in range(2**w):
        redclms_bin = format(redclms, 'b').zfill(w)
        
        rem_black = 0
        for i in range(h):
            for j in range(w):
                if redlines_bin[i] == '0' and redclms_bin[j] == '0' and board[i][j] == '#':
                    rem_black += 1
        
        if rem_black == k:
            cnt += 1

print(cnt)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

for fill_h in range(2**h):
  for fill_w in range(2**w):
    cnt = 0
    for i in range(h):
      for j in range(w):
        if (fill_h >> i)&1 == 0 and (fill_w >> j)&1 == 0:
          if matrix[i][j] == '#':
            cnt += 1
    if cnt == k:
      ans += 1
      
print(ans)

Submission status: Accepted

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

masu = []

for i in range(h):
    masu.append(list(input()))
    
count = 0

import copy

for i in range(2**h):
    for j in range(2**w):
        
        m = copy.deepcopy(masu)
        blacknum = 0
        
        for k in range(h):
            for l in range(w):
                if i>>k&1 == 0 and j>>l&1 == 0 and m[k][l] == "#":
                    blacknum = blacknum + 1
                
                    
        if blacknum == kazu:
            count = count+1
            # print(i,j)
            
print(count)

Submission status: Accepted

Solution code:
import itertools

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

lines = []
for i in range(h):
    lines.append(input())

result = 0

h_indexes = range(h)
w_indexes = range(w)

for i in range(h + 1):
    for j in range(w + 1):
        for h_index_list in itertools.combinations(h_indexes, i):
            for w_index_list in itertools.combinations(w_indexes, j):
                cnt = 0
                for h_index in h_index_list:
                    for w_index in w_index_list:
                        if '#' == lines[h_index][w_index]:
                            cnt += 1
                if cnt == k:
                    result += 1

print(result)

Submission status: Accepted

Solution code:
import copy
H, W, K = map(int, input().split())
map_info = [list(input()) for i in range(H)]
bits = H + W
count_total = 0
ans = 0

#行全パターン
for row in range(2 ** H):
    #列全パターン
    for column in range(2 ** W):
        map_updated = copy.deepcopy(map_info)
        count = 0
        #ある行パターンの中で何ビットずらすか
        for bit_row in range(H):
            count = 0
            # 行パターンをbit_rowビットだけずらして1なら赤く塗る
            if (row >> bit_row) & 1:
                map_updated[bit_row] = ['*' for i in map_updated[bit_row]]
        #ある列パターンの中で何ビットずらすか
        for bit_column in range(W):
            count = 0
            # 列パターンをbit_columnビットだけずらして1なら赤く塗る
            if (column >> bit_column) & 1:
                for j in range(H):
                    map_updated[j][bit_column] = '*'
        #黒マスカウント
        for i in range(H):
            count += map_updated[i].count('#')
        if count == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
c = []
for i in range(H):
    c.append(input())
H_flag = [0 for i in range(H)]
W_flag = [0 for j in range(W)]
ans = 0
for i in range(2 ** H):
    for k  in range(H):
        H_flag[k] = i % 2
        i = i // 2
    for j in range(2 ** W):
        for l in range(W):
            W_flag[l] = j % 2
            j = j // 2
        tmp_black = 0
        for x in range(H):
            for y in range(W):
                if H_flag[x] == 0 and W_flag[y] == 0:
                    if c[x][y] == '#':
                        tmp_black += 1
        if tmp_black == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
import numpy as np

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

ans=0
for i in range(2**H):
     for j in range(2**W):
            i_s=format(i, "0{0}b".format(H))
            j_s=format(j, "0{0}b".format(W))
            M=[[[] for _ in range(W)] for _ in range(H)]
            for h in range(H):
                for w in range(W):
                    if i_s[h]=="1" or j_s[w]=="1":
                        M[h][w]="$"
                    else:
                        M[h][w]=m[h][w]
            M_1=list(itertools.chain.from_iterable(M))
            if M_1.count("#")==K:
                ans+=1
            
print(ans)

Submission status: Accepted

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

cnt = 0
h_dict = {i: 0 for i in range(h)}
w_dict = {i: 0 for i in range(w)}
for i, c in enumerate(arr):
    cnt_h = c.count('#')
    cnt += cnt_h
    h_dict[i] = cnt_h
    for j, c_ in enumerate(c):
        if arr[i][j] == '#':
            w_dict[j] += 1

ans = 0
for bit_h in range(2**h):
    tmp_h = []
    for i in range(h):
        if (bit_h >> i) & 1:
            tmp_h.append(i)
    for bit_w in range(2**w):
        tmp_w = []
        for j in range(w):
            if (bit_w >> j) & 1:
                tmp_w.append(j)
        tmp = 0
        for h_ in tmp_h:
            tmp += h_dict[h_]
        for w_ in tmp_w:
            tmp += w_dict[w_]
        for h_ in tmp_h:
            for w_ in tmp_w:
                if arr[h_][w_] == '#':
                    tmp -= 1

        if cnt - tmp == k:
            ans += 1

print(ans)

Submission status: Accepted

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

c=[0]*h
for i in range(h):
    c[i]=input()

cnt=0

for rows in range(1<<h):
    for cols in range(1<<w):
        black=0
        for i in range(h):
            if (rows >> i) %2==1:
                continue
            for j in range(w):
                if (cols >> j) %2==1:
                    continue
                black += c[i][j] =="#"
        if black==k:
            cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
nb=0
a=[[0 for i in range(w)] for j in range(h)]
for i in range(h):
    s=input()
    for j in range(w):
        if s[j]=="#":
            a[i][j]=1
            nb+=1

res=0
for ii in range(2**h):
    for jj in range(2**w):
        cnt=nb
        for i in range(h):
            for j in range(w):
                if a[i][j]==1 and (ii&(1<<i) or jj&(1<<j)):
                    cnt-=1
        if cnt==k:
            res+=1
print(res)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
c = [input()for _ in range(h)]
ans = 0
for bit in range(1<<(h+w)):
    cnt = 0
    for i in range(h):
        if (bit>>i)&1:continue
        for j in range(w):
            if(bit>>(h+j))&1:continue
            if c[i][j] == '#':
                cnt += 1
    if cnt == k:
        ans += 1
print(ans)