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 i in range(H)]
ans = 0
for i in range(1<<H): #Yes,Noを２進数を結び付ける.<<はビットを左に移動
    for j in range(1<<W):
        cnt = 0
        for x in range(H):
            for y in range(W): #>>でビットを右に戻したときにxの部分が0であればいい
                if ((i>>x)&1 == 0) and ((j>>y)&1 == 0) and C[x][y] == '#':
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
h, w, k = [int(i) for i in input().split()]
masu = [input() for _ in range(h)]
ans = 0
for mark_h in range(2**h):
    for mark_w in range(2**w):
        black = 0
        for i in range(h):
            for j in range(w):
                if (mark_h>>i)&1==1 and (mark_w>>j)&1==1:
                    if masu[i][j]=="#":
                        black+=1
        if black==k:
            ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

H, W, K = LI()
c = SRL(H)

ans=0
 
for i in range(2**H):
    seen=[]
    for n in range(H):
        if ((i>>n) & 1):
            seen.append(c[n])
    for j in range(2**W):
        count=0
        for m in range(W):
            if ((j>>m) & 1):
                for l in range(len(seen)):
                    if seen[l][m]=="#":
                        count+=1

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

Submission status: Accepted

Solution code:
import itertools

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

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

Submission status: Accepted

Solution code:
H, W, K = [int(x) for x in input().split()]
A = []
for i in range(H):
  A.append([str(x) for x in list(input())])
ans = 0
for il in range(1<<H):
  for jl in range(1<<W):
    black = 0
    for i in range(H):
      for j in range(W):
        if ((((il>>i) & 1)==0) and (((jl>>j) & 1)==0) and (A[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 i in range(H)]

listH = [i for i in range(H)]
listW = [i for i in range(W)]
hlist = []
wlist = []
ans = 0

for i in range(1, 2**H):
  list1 = []
  for j in range(H):
    if (i >> j) &1 == 1:
      list1.append(listH[j])
  hlist.append(list1)

for i in range(1, 2**W):
  list1 = []
  for j in range(W):
    if (i >> j) &1 == 1:
      list1.append(listW[j])
  wlist.append(list1)

for i in hlist:
  for j in wlist:
    black = 0
    for x in i:
      for y in j:
        if c[x][y]=='#':
          black += 1
    if black == K:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
S=[input() for _ in range(h)]
y=0
for i in range(2**h):
  T=[S[j] for j in range(h) if (i>>j)&1]
  for l in range(2**w):
    x=0
    for m in range(w):
      if (l>>m)&1:
        for n in range(len(T)):
          if T[n][m]=='#':
            x+=1
    if x==k:
      y+=1
print(y)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
S=[input() for _ in range(h)]
x=0
for i in range(2**h):
  T=[S[j] for j in range(h) if (i>>j)&1]
  for l in range(2**w):
    U=[row[m] for row in T for m in range(w) if (l>>m)&1]
    if U.count('#')==k:
      x+=1
print(x)

Submission status: Accepted

Solution code:
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

H, W, K = MI()
mylist = []
result = 0

for i in range(H):
    temp = input().rstrip()
    temp = [temp[j] for j in range(W)]
    mylist.append(temp)

for maskH in range(0, 2**H):
    for maskW in range(0, 2**W):
        black = 0
        for i in range(0, H):
            for j in range(0, W):
                if ((maskH >> i) & 1) == 0 and ((maskW >> j) & 1) == 0 and mylist[i][j] == "#":
                    black += 1
        if black == K:
            result += 1
            
print(result)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from math import factorial
def combination(n, r):
    return factorial(n)//(factorial(n-r) * factorial(r))


h,w,k = readints()
c = [readstr() for i in range(h)]

ans = 0
for i in range(1<<h):
    for j in range(1<<w):
        black = 0
        for x in range(h):
            for y in range(w):
                if 1<<x & i and 1<<y & j and c[x][y]=='#':
                    black += 1
        if black == k:
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w,k=map(int, input().split())
S=[]
y=0
for i in range(h):
  S.append(input())
  
for i in range(2**h):
  S2=[]
  for j in range(h):
    if (i>>j)&1:
      S2.append(S[j])
  
  for l in range(2**w):
    x=0
    for m in range(w):
      if (l>>m)&1:
        for n in range(len(S2)):
          if S2[n][m]=='#':
            x+=1
    if x==k:
      y+=1
print(y)

Submission status: Accepted

Solution code:
h, w, k = map(int,input().split())
c = [list(input()) for i in range(h)]
ans = 0
for p_h in range(2**h):
    for p_w in range(2**w):
        black = 0
        for i in range(h):
            for j in range(w):
                if(p_h>>i)&1==0 and (p_w>>j)&1==0:
                    if c[i][j]=='#':
                        black += 1
        if black == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

H, W, K = map(int, input().split())
C = np.array([[i for i in input()] for j in range(H)])

ans = 0

for h_bit in range(1, 1 << H):
    for w_bit in range(1, 1 << W):
        h_count = []
        for i in range(H):
            if h_bit & (1 << i):
                h_count.append(i)

        w_count = []
        for j in range(W):
            if w_bit & (1 << j):
                w_count.append(j)
        if np.sum(C[np.ix_(h_count, w_count)] == "#") == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
H, W, K = list(map(int, input().split()))
 
c = [list(input()) for i in range(H)]
 
cnt = 0
for i in range(2**H):
    for j in range(2**W):
        cnt_black = 0
        for k in range(H):
            if (i >> k) & 1:
                continue
            for l in range(W):
                if (j >> l) & 1:
                    continue
                if c[k][l] == '#':
                    cnt_black += 1
        if cnt_black == K:
            cnt += 1
 
print(cnt)

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 = [[0] * W for _ in range(H)]
    for i in range(H):
        line = LS()
        for j, l in enumerate(line):
            if l == '#':
                G[i][j] += 1
    # print(G)
    G = np.array(G)

    ans = 0
    for i in product([0, 1], repeat=W):
        R = G * i
        for j in product([0, 1], repeat=H):
            A = R.T * j
            # print(A, A.sum())
            if A.sum() == K:
                ans += 1
    print(ans)



if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
board = [list(input()) for _ in range(h)]
ans = 0
for paint_h in range(2 ** h):
    for paint_w in range(2 ** w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if (paint_h >> i) & 1 == 0 and (paint_w >> j) & 1 == 0:
                    if board[i][j] == "#":
                        cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(2 ** H):
  for j in range(2 ** W):
    count = 0
    for ii in range(H):
      for jj in range(W):
        if (i>>ii&1) == 0 and (j>>jj&1) == 0 and c[ii][jj] == '#':
          count += 1
    if count == K:
      ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
# 行の塗り方
for rows in range(2**H):
        # 列の塗り方
    for cols in range(2**W):

        # それぞれの塗り方について、残る黒色を数える
        black = 0

        # 全てのマスを調べる
        for i in range(H):
            for j in range(W):
                # 赤で塗られない、かつ、黒色の場合
                if ((rows >> i) & 1) == 0 and ((cols >> j) & 1) == 0 and cw[i][j] == '#':
                    black += 1

        # 残る黒色の数がちょうどK個の場合
        if black == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import copy
h, w, knum = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0
ccopy = copy.deepcopy(c)
hbin = list(map(bin, list(range((2**h)))))
hbin = list(map(lambda x:x[2:], hbin))
for i,item in enumerate(hbin):
    item = "0"*(h-len(item)) + item
    hbin[i] = list(item)
wbin = list(map(bin, list(range((2**w)))))
wbin = list(map(lambda x:x[2:], wbin))
for i,item in enumerate(wbin):
    item = "0"*(w-len(item)) + item
    wbin[i] = list(item)

for i in hbin:
    ccopy = copy.deepcopy(c)
    for j,switch in enumerate(i):
        if int(switch) == 1:
            ccopy[j] = list("R"*w)
    for k in wbin:
        ccopy2 = copy.deepcopy(ccopy)
        for l,switch in enumerate(k):
            if int(switch) == 1:
                for m in range(h):
                    ccopy2[m][l] = "R"
        ccopy2 = list(map(lambda x:x.count("#"), ccopy2))
        if  knum == sum(ccopy2):
            ans += 1
        ccopy2 = copy.deepcopy(ccopy)
print(ans)

Submission status: Accepted

Solution code:
A = list(map(int,input().split()))

H = A[0]
W = A[1]
K = A[2]



c = [input() for i in range(H)]
result = 0
c_t0 = c
shape_sum = 0

for x in range(H):
    for y in range(W):
        if c[x][y] == '#':
            shape_sum += 1

for xbit in range(2**H):
    for  ybit in range(2**W):

        ban_list = [[0] * W for i in [1] * H]
        tmp = shape_sum
        c = (c_t0)
        Sx = []
        Sy = []
        for i in range(H):
            if (xbit & (1<<i)):
                for iter in range(W) :
                    if c[i][iter] == '#' and ban_list[i][iter] == 0:
                        tmp -= 1
                        # c[i][iter] = '.'
                        ban_list[i][iter] = 1
               
                Sx.append(i) 
        for i in range(W):
            if (ybit & (1<<i)):
                for iter in range(H):
                    if c[iter][i] == '#'  and ban_list[iter][i] == 0:
                        tmp -= 1 
                        ban_list[iter][i] = 1
                        # c[iter][i] = '.'               
                Sy.append(i)        
        
        if tmp == K:
            result += 1

            # print("%d H: {" % xbit, end="")
            # for i in range(len(Sx)):
            #     print(" %d" % Sx[i], end="")
            # print(" }", end="")

            # print("%d W: {" % ybit, end="")
            # for i in range(len(Sy)):
            #     print(" %d" % Sy[i], end="")
            # print(" }")


print(result)

Submission status: Accepted

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

ans = 0
for i in range(2 ** h):
    for j in range(2 ** w):
        d = [c[x][:] for x in range(h)]
        for p in range(h):
            if (1 << p) & i: 
                for q in range(w): d[p][q] = '.'
        for q in range(w):
            if (1 << q) & j: 
                for p in range(h): d[p][q] = '.'
        cnt = 0
        for p in range(h):
            for q in range(w): cnt += (d[p][q] == '#')
        ans += (cnt == k)
print(ans)

Submission status: Accepted

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

cnt = 0
for cols in range(2**H):
    for rows in range(2**W):
        black = 0
        for i in range(H):
            for j in range(W):
                if ((cols >> i) & 1) == 0 and ((rows >> j) & 1) == 0:
                    if cw[i][j] == '#':
                        black += 1
        if black == K:
            cnt += 1
print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(2 ** (h)):
    for j in range(2 ** (w)):
        bag = 0
        sharp = 0
        
        for l in range(h):
            for m in range(w):
                
                if s[l][m] == "#":
                    sharp +=1
                if ((i >> l)&1) or ((j>>m)&1):
                    if s[l][m] == "#":
                        bag += 1
                        
        if sharp - bag == k:
            ans += 1
                
print(ans)

Submission status: Accepted

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


def BlackCount(fig, cal_row, cal_col):
    N = 0
    for i in range(len(fig)):
        for j in range(len(fig[0])):
            if i not in cal_row and j not in cal_col:
                if fig[i][j] == '#':
                    N += 1
    return N


H, W, K = map(int, input().split())
fig = []
for i in range(H):
    row = list(input().rstrip('\n'))
    fig.append(row)

Nlist = list(itertools.product(range(H), range(W)))
# print(Nlist)
ans = 0
for N_row, N_col in Nlist:
    # print(N_row, N_col)
    cal_row_list = list(itertools.combinations(range(H), N_row))
    # print(cal_row_list)
    cal_col_list = list(itertools.combinations(range(W), N_col))
    # print(cal_col_list)
    for cal_row, cal_col in itertools.product(cal_row_list, cal_col_list):
        if BlackCount(fig, cal_row, cal_col) == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
import pprint

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] and col_bit[col]):
          cnt += 1
    if cnt == k:
      ans+=1

print(ans)

Submission status: Accepted

Solution code:
from itertools import product as pro

h,w,K=map(int,input().split())
C=[]
for _ in range(h):
    C.append(list(str(input())))



L=['0','1']
Sh=list(pro(L,repeat=h))
Sw=list(pro(L,repeat=w))


ans=0
for i in Sh:
    for j in Sw:
        temp=0

        for k in range(h):
            for l in range(w):
                if i[k]=='0' and j[l]=='0':
                    if C[k][l]=='#':
                        temp+=1
        
        if temp==K:
            ans+=1
           

print(ans)

Submission status: Accepted

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

#output
import itertools
A_1 = list(itertools.product([0, 1], repeat = h))
A_2 = list(itertools.product([0, 1], repeat = w))

answer = 0
for a_1 in A_1:
    for a_2 in A_2:
        temp = 0
        for i in range(h):
            for j in range(w):
                if a_1[i] and a_2[j]:
                    if c[i][j] == "#":
                        temp += 1
        if temp == k:
            answer += 1
print(answer)

Submission status: Accepted

Solution code:
H,W,K=map(int,input().split())
G=[list(input()) for i in range(H)]
ans=0
cnt_bl=0
for i in range(H):
  for j in range(W):
    if G[i][j]=="#":
      cnt_bl+=1
cnt_bl-=K
if cnt_bl<0:
  print(0);exit()


for i in range(2**W):
  for j in range(2**H):
    res=0
    for x,k in enumerate(bin(i)[2:][::-1]):
      for y,l in enumerate(bin(j)[2:][::-1]):
        #print(G[y][x],k,l,y,x)
        if k=="1" and l=="1":
          if G[y][x]=="#":
            res-=1
    for x,k in enumerate(bin(i)[2:][::-1]):
      for y in range(H):
        #print(k)
        if k=="1" and G[y][x]=="#":
          #print(y,x,k)
          res+=1
    for y,l in enumerate(bin(j)[2:][::-1]):
      for x in range(W):
        if l=="1" and G[y][x]=="#":
          res+=1
    #print(bin(i)[2:],bin(j)[2:],res)
    if res==cnt_bl:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
h,w,ppp=map(int,input().split())
lis=[]
for i in range(h):
  lis.append(str(input()))
ans=0
for i in range(0,2**h):
  h_list=[]
  for k in range(0,h):
    t=h-k-1
    amari=i//2**t
    i-=amari*2**t
    h_list.append(amari)
  for j in range(0,2**w):
    count=0
    w_list=[]
    for l in range(0,w):
      t=w-l-1
      amari=j//2**t
      j-=amari*2**t
      w_list.append(amari)
    for x in range(0,h):
      for y in range(0,w):
        if w_list[y]==0 and h_list[x]==0:
          if lis[x][y]=="#":
            count+=1
    if count==ppp:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split(' '))
ls = [0] * h
result = 0

for i in range(h):
    ls[i] = input()

for i in range(1<<h):
    for j in range(1<<w):
        cnt = 0
        for s in range(h):
            for t in range(w):
                if ((i>>s) & 1) & ((j>>t) & 1): 
                    if ls[s][t] == '#':
                        cnt += 1
        if cnt == k:
            result += 1
print(result)

Submission status: Accepted

Solution code:
# C - H and V
def get_grid(H):
	grid = []
	
	for i in range(H):
		grid.append(input())

	return grid


def get_combis(n):
	import itertools
	numbers = list(range(n))
	combis = []

	for i in range(n + 1):
		arr = list(itertools.combinations(numbers, i))
		
		for a in arr:
			combis.append(set(a))
	
	return combis


def count_black(h, w):
	global grid
	global H
	global W
	
	count = 0
	
	for i in range(H):
		for j in range(W):
			if grid[i][j] == '#':
				if not i in h and not j in w:
					count += 1
	
	return count


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

h_combis = get_combis(H)
w_combis = get_combis(W)
ans = 0

for h in h_combis:
	for w in w_combis:
		if count_black(h, w) == K:
			ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,m,k = map(int,input().split())

arr = []
for _ in range(n):
  arr.append(list(input()))
ans = 0  
for i in range(1<<n):
  for j in range(1<<m):
    black = 0
    for q in range(n):
      for r in range(m):
        if i & (1<<q) and j & (1<<r) and arr[q][r] == "#":
          black += 1
    if black == k: ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

h,w,k = map(int,input().split())
hw=[]
hwwk=[]
for i in range(h):
    hwwk.append(input())
    hw.append([1 if hwwk[i][j]=='#' else 0 for j in range(w)])
ahw=np.array(hw)
an=0
wk=np.zeros((h,w),int)
wwwk=0
for i in range(1,2**h):
    for j in range(h):
        bit=i>>j&1
#        print(bit)
        if bit!=0:
            wk[j]=ahw[j]
    #try:
     #   wwk=np.sum(wk,axis=1)
    #except:
     #   wwk=wk
    wwk=np.sum(wk,axis=0)
#    print(wk,wwk)
    for kk in range(1,2**w):
        for l in range(w):
            wbit=kk>>l&1
            if wbit!=0:
                wwwk+=wwk[l]
        if wwwk==k:
            an+=1
        wwwk=0
    wk=np.zeros((h,w),int)

print(an)

Submission status: Accepted

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

c = []

for _ in range(H):
    c.append(list(input()))

ans = 0

for mask_r in range((1 << H)):
    for mask_c in range(1 << W):
        black = 0
        for i in range(H):
            for j in range(W):
                if (
                    ((mask_r >> i) & 1) == 0
                    and ((mask_c >> j) & 1) == 0
                    and c[i][j] == "#"
                ):
                    black += 1
        if black == K:
            ans += 1
print(ans)

Submission status: Accepted

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

def main():
    H, W, K = map(int, input().split())
    C = [list(input().rstrip()) for i in range(H)]
    ans = 0
    for i in range(1<<H):
        for j in range(1<<W):
            CNT = 0
            for s in range(H):
                for t in range(W):
                    if (i>>s) & 1:
                        continue
                    if (j >> t) & 1:
                        continue
                    if C[s][t] == '#':
                        CNT += 1
            if CNT == K:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import copy

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

def check_squares(H_mask, W_mask, squares):
    for i, x in enumerate(f'{H_mask:0{H}b}'):
        if int(x):
            squares[i] = ['R'] * W
    
    for i_1, x in enumerate(f'{W_mask:0{W}b}'):
        if int(x):
            for i_2 in range(H):
                squares[i_2][i_1] = 'R'
                
    return sum([x.count('#') for x in squares])


for H_mask in range((1 << H)):
    for W_mask in range((1 << W)):
        #print(f'{H_mask:0{H}b} {W_mask:0{W}b}')
        #print(check_squares(H_mask, W_mask, copy.deepcopy(squares)))
        c = check_squares(H_mask, W_mask, copy.deepcopy(squares))
        if c == K:
            result += 1
            
print(result)

Submission status: Accepted

Solution code:
def solve(h, w, k, C):
    total = 0
    for r in range(h):
        for c in range(w):
            if C[r][c] == "#":
                total += 1
    ans = 0
    for mask in range(1<<(h+w)):
        num = 0
        for r in range(h):
            for c in range(w):
                ok = ((mask & (1<<c)) or (mask & (1<<(w+r)))) and (C[r][c] == "#")
                if ok:
                    num += 1
        if total - num == k:
            ans += 1
    return ans

h, w, k = map(int, input().split())
C = [input() for r in range(h)]
print(solve(h, w, k, C))

Submission status: Accepted

Solution code:
import numpy as np

H,W,K=map(int,input().split())
c=[]
for i in range(H):
    c.append(list(input()))
ans = 0
for i in range(2**H):
    for j in range(2**W):
        count = 0
        for ii in range(H):
            for jj in range(W):
                if (i>>ii&1)==0 and (j>>jj&1)==0 and c[ii][jj]=='#':
                    count +=1
        if count == 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] and col_bit[col]):
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
import copy

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

black = 0
for i in range(h):
    black += c[i].count('#')

cc = copy.deepcopy(c)

ans = 0
for i in range(2 ** h):
    for j in range(2 ** w):
        paint_h = [-1] * h
        paint_w = [-1] * w
        for s in range(h):
            if ((i >> s) & 1):
                paint_h[h - 1 - s] = 1
        for s in range(w):
            if ((j >> s) & 1):
                paint_w[w - 1 - s] = 1
        #print(paint_h,paint_w)

        painted = 0
        for s in range(h):
            if paint_h[s] == 1:
                for t in range(w):
                    if c[s][t] == '#':
                        c[s][t] = '.'
                        painted += 1
        for s in range(w):
            if paint_w[s] == 1:
                for t in range(h):
                    if c[t][s] == '#':
                        c[t][s] == '.'
                        painted += 1

        if black - painted == k:
            ans += 1

        c = copy.deepcopy(cc)

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(1<<h): #bitシフト
    for j in range(1<<w): #bitシフト
        b = 0
        for y in range(h):
            for x in range(w):
                if i>>y&1 and j>>x&1 and c[y][x] == "#":
                    b+=1
        if b==k:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import sys
#input=sys.stdin.readline
sys.setrecursionlimit(3000)
import re
import math
import itertools
import collections
import bisect
import fractions
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.1415926535897932
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]
# fractions.gcd(x,y)
def lcm(a,b): return a*b//fractions.gcd(a,b)
def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0
def eof(t): print(t); exit()


h,w,k=map(int,input().split())
d=[input() for i in range(h)]
ans=0
chk=2**(h+w)
for i in range(chk):
    a="000000000000"+bin(i)[2:]
    a=a[::-1]
    cnt=0
    for j in range(h*w):
        y=j//w
        x=j%w
        if a[y]=="0" and a[h+x]=="0" and d[y][x]=="#":
            cnt+=1
    if cnt==k:
        ans+=1


print(ans)

Submission status: Accepted

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

ans = 0
hyou = [0] * H
for i in range(H):
    hyou[i] = input()

for h in range(1 << H):
    for w in range(1 << W):
        count = 0
        for i in range(H):
            if(h >> i) % 2 == 1:
                continue
            for j in range(W):
                if(w >> j) % 2 == 1:
                    continue
                count += hyou[i][j] == "#"
        ans += count == K

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(1 << H):
    for j in range(1 << W):
        count = 0
        for m in range(H):
            for l in range(W):
                if i >> m & 1 or j>> l & 1:
                    continue 
                if c[m][l] == '#':
                   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))
ans = 0
for i in range(1<<h):
    for j in range(1<<w):
        b = 0
        for y in range(h):
            for x in range(w):
                if i>>y&1 and j>>x&1 and c[y][x] == "#":
                    b+=1
        if b==k:
            ans+=1
print(ans)

Submission status: Accepted

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

h,w,k = map(int,input().split())
x = []
for i in range(h):
    x.append(list(map(int,list(input().rstrip().replace(".","0").replace("#","1")))))
#print(x)
#h,w = 2,3
count = 0
for i in range(1,max(2,2**h)):
    y = list(map(int,format(i,"0"+str(h)+"b")))
    for j in range(1,max(2,2**w)):
        z = list(map(int,format(j,"0"+str(w)+"b")))
        #print(i,j,y,z)
        sum0 = 0
        for l in range(w):
            for m in range(h):
                sum0 += y[m] * z[l] * x[m][l]
        if sum0 ==k:
            count += 1
print(count)