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
import copy
import itertools
h,w,k = map(int, input().split())
s = [list(input()) for i in range(h)]
data = np.zeros(h*w).reshape(h,w)
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            data[i][j] = 1
 
ans = 0
## 塗らない場合
if np.sum(data == 1) == k:
    ans = 1
## すべて塗った場合
if k == 0:
    ans = 1
 
a = list()
b = list()
for i in range(1,h):
    a += list(itertools.combinations(range(h), i))
for i in range(1,w):
    b += list(itertools.combinations(range(w), i))
 
for i in a:
    for j in b:
        temp = data.copy()
        temp[i,:] = 2
        temp[:,j] = 2
        if np.sum(temp == 1) == k:
            ans += 1
 
for i in a:
    temp = data.copy()
    temp[i,:] = 2
    if np.sum(temp == 1) == k:
        ans += 1
        
for j in b:
    temp = data.copy()
    temp[:,j] = 2
    if np.sum(temp == 1) == 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())
t = 2**(h+w)
ans = 0
for i in range(t):
  tc = c[:]
  b = format(i, 'b').zfill(h+w)
  for j in range(len(b)):
    if b[j] == "1":
      if j < h:
        tc[j] = "?"*w
      else:
        for l in range(h):
          tc[l] = tc[l][:(j-h)] + "?" + tc[l][(j-h+1):]
  cn = 0
  for j in range(h):
    cn += tc[j].count("#")
  if cn == k:
    ans += 1
print(ans)

Submission status: Accepted

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

for i in range(H):
    ls.append(list(input()))

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

Submission status: Accepted

Solution code:
from  itertools import combinations as cmb
import copy 

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

C = []
ans = 0

for i in range(H):
  C.append(list(input()))

for i in range(H):#選ぶ列数
  for j in range(W):#選ぶ行数
    for hs in cmb(range(H),i):#選ぶ列数の組み合わせ
      for ws in cmb(range(W),j):#選ぶ行数の組み合わせ
        tmpC = copy.deepcopy(C)#操作用配列
        for h in hs:
          tmpC[h] = ["" for k in range(W)]#その列を消す
        for w in ws:
          for k in range(H):
            tmpC[k][w]="" #その行を消す
        #print(tmpC,hs,ws,sum(tmpC,[]).count("#")==K)
        if sum(tmpC,[]).count("#")==K:
          ans +=1    
print(ans)

Submission status: Accepted

Solution code:
h, w, f = list(map(int, input().split()))
c = [input() for i in range(h)]
count = 0
bit_h = []
for k in range(2**h):
    hh = []
    for l in range(h):
        if((k >> l) & 1):
            hh.append(1)
        else:
            hh.append(0)
    bit_h.append(hh)

bit_w = []
for i in range(2**w):
    ww = []
    for j in range(w):
        if((i >> j) & 1):
            ww.append(1)
        else:
            ww.append(0)
    bit_w.append(ww)

ans = 0
for i in range(len(bit_h)):
    for j in range(len(bit_w)):
        count = 0
        for k in range(h):
            for l in range(w):
                if bit_h[i][k] == 1 and bit_w[j][l] == 1 and c[k][l] == "#":
                    count += 1
        if count == f:
            ans += 1
print(ans)

Submission status: Accepted

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

ans=0

for i in range(2**H):
	for j in range(2**W):
		cnt=0
		for k in range(H):
			for l in range(W):
				if c_map[k][l]=='#' and (i>>k)&1==0 and (j>>l)&1==0:
					cnt+=1
		if cnt==K:
			ans+=1

print(ans)

Submission status: Accepted

Solution code:
import math
import copy

ans = 0

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

for i in range(int(math.pow(2, H+W))):
    i_bin = ''.join(list(reversed(format(i, 'b').zfill(100))))
    C = copy.deepcopy(c)
    for h in range(H):
        if i_bin[h] == '1':
            for w in range(W):
                C[h][w] = '.'
    for w in range(W):
        if i_bin[H + w] == '1':
            for h in range(H):
                C[h][w] = '.'
    count = 0
    for h in range(H):
        count += C[h].count('#')
    if count == K:
        ans += 1

print(ans)

Submission status: Accepted

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

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

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
        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(' '))
ls = []

for i in range(H):
    ls.append(list(input()))

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

Submission status: Accepted

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

ans = 0
for hi in range(2 ** h):
    hs = set()
    for hj in range(h):
        if (hi >> hj) & 1:
            hs.add(hj)
    for wi in range(2 ** w):
        ws = set()
        for wj in range(w):
            if (wi >> wj) & 1:
                ws.add(wj)
        cnt = 0
        for i in range(h):
            if i in hs:
                continue
            for j in range(w):
                if j in ws:
                    continue
                if c[i][j] == "#":
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

ans = 0
for i in itertools.product(range(2),repeat=H):
  for j in itertools.product(range(2),repeat=W):
    black = 0
    for h in range(H):
      for w in range(W):
        if i[h] == 0 and j[w] == 0 and G[h][w] == '#':
          black += 1
    ans += (black == K)

print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
c = [list(input()) for i in range(h)]
ans = 0
for p in range(1<<h):
    for q in range(1<<w):
        black = 0
        for m in range(h):
            for n in range(w):
                if (p>>m)&1 == 0 and (q>>n)&1 == 0 and c[m][n] == "#":
                    black += 1
        if black == 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()

ans = 0
for rows in range(1 << h):
    for cols in range(1 << w):
        b_cnt = 0
        for _h in range(h+1):
            if not (rows >> _h) & 1:
                continue
            for _w in range(w+1):
                if not (cols >> _w) & 1:
                    continue
                if c[_h][_w] == '#':
                    b_cnt += 1
        if b_cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import copy
H,W,n_black = map(int,input().split())
grid = [list(input()) for _ in range(H)]
for y in range(H):
    for x in range(W):
        if grid[y][x] == "#":
            grid[y][x] = 1
        else:
            grid[y][x] = 0
num_pat = 2**(H+W)
ans = 0
for i in range(num_pat):
    now_grid = copy.deepcopy(grid)
    for j in range(H+W):    
        if i>>j & 1:
            if j < H:
                for x in range(W):
                    now_grid[j][x] = 0
            else:
                j -= H
                for y in range(H):
                    now_grid[y][j] = 0
    black = 0
    for y in range(H):
        black += sum(now_grid[y])
    if black == n_black:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
# input here
_INPUT = """\
2 3 2
..#
###
"""

def main():
    H, W, K = map(int, input().split())
    grid = [input() for _ in range(H)]
    
    n = H + W
    ans = 0
    for i in itertools.product(range(2), repeat=H):
        for j in itertools.product(range(2), repeat=W):
            cnt = 0            
            for y in range(H):
                if i[y]:
                    continue
                for x in range(W):
                    if j[x]:
                        continue
                    if grid[y][x] == "#":
                            cnt += 1
            if cnt == K:
                ans += 1
    print(ans)

if __name__ == '__main__':
    import io
    import sys
    import math
    import itertools

    # sys.stdin = io.StringIO(_INPUT)
    main()

Submission status: Accepted

Solution code:
import itertools

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

ans = 0

for i in range(H+1):
    for j in range(W+1):
        for m in itertools.combinations(list(range(H)), i):
            for n in itertools.combinations(list(range(W)), j):
                count = 0
                for a in m:
                    for b in n:
                        if(C[a][b] == "#"):
                            count += 1
                if(count == K):
                    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import copy

H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]
k = sum([ci.count("#") for ci in c])
ans = 0

for i2 in range(2 ** H):
  for j2 in range(2 ** W):
    cr = copy.deepcopy(c)
    for k in range(H+1):
      if i2 & 2**k == 2**k:
        for j in range(W):
          cr[k][j] = "$"
    for l in range(W+1):
      if j2 & 2**l == 2**l:
        for i in range(H):
          cr[i][l] = "$"
    if K == sum([ci.count("#") for ci in cr]):
      ans += 1
    
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 n in range(h):
			for m in range(w):
				if i >> n & 1:
					continue
				if j >> m & 1:
					continue
				if c[n][m] == '#':
					cnt += 1
		if cnt == k:
			ans += 1
print(ans)

Submission status: Accepted

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

import numpy
from copy import deepcopy

def binary(x, n):
  l = []
  for i in range(n):
    l.append(x%2==1)
    x //= 2
  return l

def main():
  h, w, k = map(int, input().strip().split())
  mat = numpy.array([[1 if c=='#' else 0 for c in input().strip()] for _ in range(h)])
  
  def f(mat, i, j):
    mat[binary(i, h)] = 0
    mat[:, binary(j, w)] = 0
    return mat.sum() == k
  
  cnt = 0
  for i in range(2 ** h):
    for j in range(2 ** w):
      if f(deepcopy(mat), i, j):
        cnt += 1
  print(cnt)
      
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]
ans = 0
for maskR in range(1 << H):
    for maskC in range(1 << W):
        black = 0
        for i in range(H):
            for j in range(W):
                if ((maskR >> i) & 1) == 0 and ((maskC >> j) & 1) == 0 and C[i][j] == '#':
                    black += 1
        if black == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
import copy

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

w = list(range(W))
h = list(range(H))
for i in range(W+1):
    for comi in combinations(w, i):
        for j in range(H+1):
            for comj in combinations(h, j):
                tmpC = copy.deepcopy(C)
                for ci in comi:
                    for hj in range(H):
                        tmpC[hj][ci] = '.'
                for cj in comj:
                    for wi in range(W):
                        tmpC[cj][wi] = '.'
                tmp = 0
                for tc in tmpC:
                    tmp += tc.count('#')
                if tmp == K:
                    ans += 1

print(ans)

Submission status: Accepted

Solution code:
def Qc():
    """
    塗りつぶされた列をbitに置き換えて探索する
    """
    h, w, k = map(int, input().split())
    lines = [input() for v in range(h)]
    ans = 0
    for ir in range(2 ** h):
        for ic in range(2 ** w):
            cnt = 0
            for i in range(h):
                for j in range(w):
                    if (ir >> i) & 1 and (ic >> j) & 1:
                        if lines[i][j] == '#':
                            cnt += 1
            if cnt == k:
                ans += 1
    print(ans)


if __name__ == '__main__':
    Qc()

Submission status: Accepted

Solution code:
import copy

h, w, k = map(int, input().split())
grd = [list(i for i in input()) for _ in range(h)]
ans = 0
for i in range(2**h):
    grd1 = copy.deepcopy(grd)
    for i1 in range(h):
        if i >> i1 & 1:
            grd1[i1] = ['r'] * w
    for j in range(2**w):
        grd2 = copy.deepcopy(grd1)
        for j1 in range(w):
            if j >> j1 & 1:
                for n in range(h):
                    grd2[n][j1] = 'r'

        if sum(grd2,[]).count('#') == k:
            ans += 1
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 cnt in range(2**(H+W)):
    h = []
    w = []
    tmp = 0
    for i in range(H):
        if cnt >> i & 1:
            h += [i]
    for i in range(W):
        if cnt >> (i+H) & 1:
            w += [i]
    for i in range(H):
        for j in range(W):
            if (C[i][j] == "#") and (not i in h) and (not j in w):
                tmp += 1
    if tmp == K:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#k = int(input())
h, w,k = map(int, input().split())
#al = list(map(int, input().split()))
cl=[list(input()) for i in range(h)]
import itertools
import copy
def countBlack(l):
    res=0
    for li in l:
        res+= li.count('#')
    return res

rows=[0,1]
cols=[0,1]
ans=0
for rowpt in itertools.product(rows,repeat=h):
    for colpt in itertools.product(cols,repeat=w):
        cl_temp=copy.deepcopy(cl)
        # 行を塗る
        for i in range(h):
            if rowpt[i]==1:
                for j in range(w):
                    cl_temp[i][j]='r'
        for j in range(w):
            if colpt[j]==1:
                for i in range(h):
                    cl_temp[i][j]='r'
        if countBlack(cl_temp)==k:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
# import sys
# input = sys.stdin.readline
import itertools
import collections
from decimal import Decimal
from functools import reduce


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    H, W, k = input_list()
    maze = [list(input()) for _ in range(H)]
    ans = 0
    for row_bit in itertools.product(range(2), repeat=H):
        for col_bit in itertools.product(range(2), repeat=W):
            cnt = 0
            for row in range(H):
                for col in range(W):
                    if maze[row][col] == "#" and (row_bit[row] and col_bit[col]):
                        cnt += 1
            if cnt == k:
                ans += 1
    print(ans)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d + 1
                black_cells.append((new_h, new_w))
    return d


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


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

c = []
b_h = [0] * H
b_w = [0] * W
b = 0

for h in range(H):
    c.append(input().rstrip())
    for w in range(W):
        if c[h][w] == "#":
            b_h[h] += 1
            b_w[w] += 1
            b += 1

ans = 0
for hi in range(2 ** H):
    for wi in range(2 ** W):
        bsum = b

        for h in range(H):
            if hi & (2 ** h) != 0:
                bsum -= b_h[h]
                for w in range(W):
                    if wi & 2 ** w != 0:
                        if c[h][w] == '#':
                            bsum += 1

        for w in range(W):
            if wi & (2 ** w) != 0:
                bsum -= b_w[w]

        if bsum == K:
            ans += 1

print(ans)

Submission status: Accepted

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

sum=0
X = 2**H-1
Y = 2**W-1

x=X
while(x):
    y=Y
    while(y):
        S=0
        for i in range(H):
            for j in range(W):
                if B[i][j]=='#' and (1<<i)&x and (1<<j)&y:
                    S+=1
        if S==K:
            sum+=1
        y = (y-1) & 2**W-1
    x = (x-1) & 2**H-1
print(sum)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import combinations

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

for i in range(H):
    G_.append(list(input()))

count = 0
g = 0
for cr in range(2**H):
    G = [G_[r][:] for r in range(H)]
    # row
    for r in range(H):
        if cr & (1 << r):
            G[r] = list('R' * W)
    # col
    for cc in range(2**W):
        G0 = [G[r][:] for r in range(H)]
        for c in range(W):
            if cc & (1 << c):
                for r in range(H):
                    G0[r][c] = 'R'
        b = sum(r.count("#") for r in G0)
        if b == K:
            count += 1
        g+=1
print(count)

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): #すべての行の塗りつぶし方を2進数で列挙する
 for paint_w in range(2**w): #すべての列の塗りつぶし方を2進数で列挙する
   cnt=0
   for i in range(h): #すべてのi行目j列目の要素についてみる
     for j in range(w):
       if (paint_h>>i)&1==0 and (paint_w>>j)&1==0: #各行のi番目のビットと各列のj番目のビットがともに0であればそのマスは塗りつぶされない
         if board[i][j]=='#': #塗りつぶされないマスが黒マスであれば個数を+1する
           cnt+=1
   if cnt==k: #塗りつぶされない黒マスの個数がKに等しければ答えを+1する
     ans+=1
print(ans)

Submission status: Accepted

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

for i in range(2 ** h):
  for j in range(2 ** w):
    i_s = []
    j_s = []
    for x in range(h):  
      if ((i >> x) & 1): 
        i_s.append(x)  
    for y in range(w):  
      if ((j >> y) & 1): 
        j_s.append(y)  
    b_s = 0
    for i_t in i_s:
      for j_t in j_s:
        if c[i_t][j_t] == "#":
          b_s += 1
    if b_s == k:
      res += 1
print(res)

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:
h, w, k = map(int, input().split())
c = list(input() for _ in range(h))
# print(c)

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())
c=[list(input())for i in range(h)]
d=0
for i in range(2**h):
    for j in range(2**w):
        x=bin(i)[2:]
        y=bin(j)[2:]
        x="0"*(h-len(x))+x
        y="0"*(w-len(y))+y
        p=0
        for s in range(h):
            for t in range(w):
                if x[s]==y[t]=="0" and c[s][t]=="#":
                    p+=1
        if p==k:
           d+=1
print(d)

Submission status: Accepted

Solution code:
H,W,K=map(int,input().split())
c = []
ans = 0

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

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

        if tmp == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
A = list(map(int, input().split()))
H = A[0]
W = A[1]
K = A[2]

colors = []
for line in range(H):
    color = input()
    color = list(color)
    colors.append(color)
ans = 0
for i in range(2**H):
    for j in range(2**W):
        cnt = 0
        for k in range(H):
            for l in range(W):
                if list(format(i,"0"+str(H)+"b"))[k] == "0" and list(format(j,"0"+str(W)+"b"))[l] == "0":
                    if colors[k][l] == "#":
                        cnt += 1
        if cnt == K:
            ans+= 1
print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
A =[]
for i in range(h):
    a = input()
    A.append([a[i] == "#" for i in range(w)])
ans = 0
for bit in range(1 << h):
    for tib in range(1 << w):
        now = 0
        for i in range(h):
            for j in range(w):
                if(bit >> i) & 1 == 0 and (tib >> j) & 1 == 0 and A[i][j] == True: now += 1
        if now == k: ans += 1
print(ans)

Submission status: Accepted

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

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

ans=0

for hei in itertools.product(range(2),repeat=h):
  for wid in itertools.product(range(2),repeat=w):
    cnt=0
    for i in range(h):
      for j in range(w):
        if hei[i]==1 and wid[j]==1 and lst[i][j]=="#":
          cnt+=1
    
    if cnt==k:
      ans+=1

    
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
table = []
ans = 0
for _ in range(H):
    li = input()
    table.append(li)
for i in range(2**H):
    for j in range(2**W):
        counter = 0
        for k in range(H):
            for l in range(W):
                if (i>>k)&1 and (j>>l)&1 and table[k][l] == "#":
                    counter += 1
        if counter == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
B = [list(input()) for _ in range(H)]
T = 0
for i_1 in range(2**H):
  for i_2 in range(2**W):
    X = [j_1 for j_1 in range(H) if (i_1>>j_1)&1]
    Y = [j_2 for j_2 in range(W) if (i_2>>j_2)&1]
    S = 0
    for x in X:
      for y in Y:
        if B[x][y]=="#":
          S += 1
    if S==K:
      T += 1
print(T)

Submission status: Accepted

Solution code:
import copy
 
H, W, K = map(int, input().split())
tiles = [list(input()) for _ in range(H)]
count  = 0
 
for num in range(2**(H+W)):
  copied_tiles = copy.deepcopy(tiles)
  for i in range(H+W):
    if num>>i&1:
      if i < H:
        for j in range(W):
          copied_tiles[i][j] = 'R'
      else:
        for j in range(H):
          copied_tiles[j][i-H] = 'R'
  black_c = 0
  for i in range(H):
    for j in range(W):
      if copied_tiles[i][j] == '#':
        black_c += 1
  if black_c == K:
    count += 1
print(count)

Submission status: Accepted

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

for bit in range(1<<h):
    for tib in range(1<<w):
        now=0
        for i in range(h):
            for j in range(w):
                if (bit>>i) &1==0 and (tib>>j)&1==0 and A[i][j]==1: now+=1
        if now==k : ans+=1
print(ans)

Submission status: Accepted

Solution code:
import itertools

h,w,k=map(int,input().split())
matrix=[]
for i in range(h):
	s=list(input())
	matrix.append(s)
hlist=[]
for i in range(h):
	hlist.append(i)
wlist=[]
for i in range(w):
	wlist.append(i)
rows=[]
cols=[]
for i in range(h+1):
	obj=itertools.combinations(hlist, i)
	rows+=list(obj)
for i in range(w+1):
	obj=itertools.combinations(wlist, i)
	cols+=list(obj)
ans=0
for i in rows:
	for j in cols:
		count=0
		for a in range(h):
			for b in range(w):
				if(matrix[a][b]=='#' and a not in i and b not in j):
					count+=1
		if(count==k):
			ans+=1
print(ans)

Submission status: Accepted

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

    # 選ばない:0  選ぶ:1

    for row in range(2 ** H):
        for column in range(2 ** W):
            cnt = 0
            for i in range(H):
                for j in range(W):
                    if row >> i & 1:
                        continue
                    if column >> j & 1:
                        continue
                    if c[i][j] == "#":
                        cnt += 1
            if cnt == K:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 0

for i in range(2**h):
    for j in range(2**w):
        count = 0
        for m in range(h):
            for l in range(w):
                if (i>>m)&1==0 and (j>>l)&1==0 and grid[m][l] == "#":
                    count+=1
        if count == k: ans+=1
print(ans)

Submission status: Accepted

Solution code:
import copy
H,W,K=map(int,input().split())
L=[[x for x in input()] for i in range(H)]
ans=0
for i in range(2**H):
    for j in range(2**W):
        C=copy.deepcopy(L)
        for k in range(H):
            if (i>>k&1):
                C[k]=["r"]*W
        for l in range(W):
            if (j>>l&1):
                for m in range(H):
                    C[m][l]="r"
        count=0
        for p in range(H):
            for q in range(W):
                if C[p][q]=="#":
                    count+=1
        if count==K:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import copy
H,W,K=input().split()
H=int(H)
W=int(W)
K=int(K)
C= [list(input()) for i in range(H)]
counter=0
for j in range(1<<H+W):
    D=copy.deepcopy(C)
    for k in range(H+W):
        mask=1<<k
        if j&mask!=0:
            if k<W:
                for l in range(H):
                    D[l][k]='R'
            else:
                for m in range(W):
                    D[k-W][m]='R'
    black=sum(D,[]).count('#')
    if black==K:
        counter+=1
print(counter)

Submission status: Accepted

Solution code:
import copy

H,W,K = input().split()
H = int(H)
W = int(W)
K = int(K)
c = list(input() for i in range(H))
for j in range(H):
    c[j] = list(c[j])
    
def wise(a,masu):#a行の塗りつぶし
    for w in range(W):
        masu[a][w] = 'r'
    return masu
        
def hight(b,ban):#b列の塗りつぶし
    for h in range(H):
        ban[h][b] = 'r'    
    return ban

count = 0
#2**(H+W)は2進数で1 << (H+W)と書ける
for j in range(1<<(H+W)):
    bunsin = copy.deepcopy(c)#コピーを定義しておくことでCの形を戻す
    for k in range((H+W)):
        mask = 1 << k
        if j & mask != 0:
            if k < W:#列の処理
                hight(k, bunsin)
                
            else :#行の処理
                wise(k - W, bunsin)
              
    new_c = []
    for l in range(H):#copyから'#を取り出す'
        for m in range(W):
            new_c.append(bunsin[l][m])
    count_black = new_c.count('#')
    if count_black == K:
        count += 1
print(count)

Submission status: Accepted

Solution code:
from itertools import product

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


def n_black(fillh, fillw):
    n = 0
    for ih, iw in product(range(h), range(w)):
        if (not fillh[ih]) and (not fillw[iw]) and c[ih][iw] == "#":
            n += 1
    return n


answer = 0
for fillh, fillw in product(
    product([True, False], repeat=h), product([True, False], repeat=w)
):
    if n_black(fillh, fillw) == k:
        answer += 1
print(answer)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
def count(li):
    black = 0
    for i in range(h):
        for j in range(w):
            if li[i][j] == "#":
                ans += 1
    return black
        
h,w,k = MI()
c = [list(input()) for _ in range(h)]
ans = 0
for bit in range(1<<h):
    for bit2 in range(1<<w):
        black = 0
        for i in range(h):
            for j in range(w):
                if ((bit >> i) & 1) == 0 and ((bit2 >> j) & 1) == 0:
                    if c[i][j] == "#":
                        black += 1
        if black == k:
            ans += 1
print(ans)