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())

a = [list(input()) for _ in range(H)] #listの中にlist()を標準入力する。H行分作成する。
#a = np.zeros((int(H),int(W)))

ans = 0
for i in range(2**H): #行の塗り方のパターン
    for j in range(2**W): #列の塗り方のパターン
        count = 0
        for s in range(H):
            for t in range(W):
                if(i >> s)&1 and (j>>t) & 1 and a[s][t] =="#":
                    count += 1
        if count == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
 
def main():
  H,W,K = map(int,input().split())
  a = []
  for i in range(H):
    a.append(sys.stdin.readline())
    
  ans = 0
  for i in range(2**H):
    for j in range(2**W):
      cnt = 0
      for s in range(H):
        for t in range(W):
          if(i >> s) & 1 and (j >> t) & 1 and a[s][t] == "#":
            cnt += 1
      if cnt == K :
        ans += 1
  print(ans)
  
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))

# ===CODE===

eps = 10 ** (-9)


def main():
    h, w, k = ns()
    c = [list(input()) for _ in range(h)]

    ans = 0
    for i in range(2 ** w):
        wlist = [1 for _ in range(w)]
        for t in range(w):
            if i >> t & 1:
                wlist[t] = 0

        for j in range(2 ** h):
            hlist = [1 for _ in range(h)]
            for t in range(h):
                if j >> t & 1:
                    hlist[t] = 0

            cnt = 0
            for x in range(w):
                for y in range(h):
                    if c[y][x] == "#" and wlist[x] and hlist[y]:
                        cnt += 1

            if cnt == k:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

H, W, K = map(int, readline().split())
C = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W]

C = 1 * (C == b'#')

def f(C, x, y):
    D = C.copy()
    for i in range(H):
        if x & (1 << i):
            D[i] = 0
    for i in range(W):
        if y & (1 << i):
            D[:, i] = 0
    return D.sum() == K

ans = 0
for x in range(1 << H):
    for y in range(1 << W):
        ans += f(C, x, y)
print(ans)

Submission status: Accepted

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

sheet = []

cnt = 0

def getPatterns(n):
    ans = []
    for i in range(2 ** n):
        op = ["-"] * n  # あらかじめ ["-", "-", "-"] というリストを作っておく
        for j in range(n):
            if ((i >> j) & 1):
                op[n - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き
        ans.append(op)
    
    return ans


for i in range(H):
    s = input()
    cnt += s.count('#') 
    a = []
    for j in range(W):
        a.append(s[j])
    sheet.append(a)

H_pattern = getPatterns(H)
W_pattern = getPatterns(W)

test_sheet = []

ans = 0


for i in H_pattern:
    test_sheet = []
    for x in range(len(i)):
        if i[x] == "-":
            test_sheet.append(sheet[x])
    for j in W_pattern:
        test_cnt = 0
        for y in range(len(j)):
            if j[y] == "-":
                for z in test_sheet:
                    if z[y] == "#":
                        test_cnt += 1
        if test_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): # 列の塗り方のパターン

      d = [c[x][:] for x in range(h)]

      for p in range(h):
         bit = (1 << p)
         if i & bit > 0: 
            for x in range(w): d[p][x] = '*'

      for q in range(w):
         bit = (1 << q)
         if j & bit > 0: 
            for x in range(h): d[x][q] = '*'

      s = 0
      for p in range(h):
         for q in range(w): 
            if d[p][q] == '#': s += 1

      if s == k: ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

import numpy as np

def resolve():
    H, W, K = map(int, input().split())
    c = np.array([list(input()) for _ in range(H)])
    h_list = [np.count_nonzero(cc == '#') for cc in c]
    w_list = [np.count_nonzero(cc == '#') for cc in c.transpose()]
    ans = 0
    total = sum(w_list)

    for i in range(2 ** H):
        for j in range(2 ** W):
            tmp_ans = 0
            tmp_h = []
            tmp_w = []

            for k in range(H):
                if ((i >> k) & 1):  # 2進数表記して、論理積を取る
                    tmp_ans += h_list[k]
                    tmp_h.append(k)

            for l in range(W):
                if ((j >> l) & 1):  # 2進数表記して、論理積を取る
                    tmp_ans += w_list[l]
                    tmp_w.append(l)

            for hh in tmp_h:
                for ww in tmp_w:
                    if c[hh, ww] == '#':
                        tmp_ans -= 1

            if total - tmp_ans == K:
                ans += 1
    
    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 3 2
..#
###"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2 3 4
..#
###"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """2 2 3
##
##"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """6 6 8
..##..
.#..#.
#....#
######
#....#
#....#"""
        output = """208"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
import sys


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


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    H, W, K = map(int, input().split())
    C = [list(input()) for _ in range(H)]
    answer = 0
    for i in range(2 ** H):
        for j in range(2 ** W):
            black = 0
            for h in range(H):
                for w in range(W):
                    if (i >> h) & 1 == 0 and (j >> w) & 1 == 0 and C[h][w] == "#":
                        black += 1
            if black == K:
                answer += 1
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

# print(bin(5>>1&1))

Submission status: Accepted

Solution code:
import sys 

def A():
  n = int(sys.stdin.readline().rstrip())
  charge = (n+999)//1000 * 1000 - n
  print(charge)


from collections import Counter
def B():
  n, *s = sys.stdin.read().split() 
  c = Counter(s)
  for v in 'AC, WA, TLE, RE'.split(', '):
    print(f'{v} x {c[v]}')


def C():
  h, w, k = map(int, sys.stdin.readline().split())
  c = [sys.stdin.readline().rstrip() for _ in range(h)]
  tot = 0
  for i in range(1<<h):
    for j in range(1<<w):
      cnt = 0
      for y in range(h):
        for x in range(w):
          if i>>y & 1 or j>>x & 1:
            continue 
          cnt += c[y][x] ==  '#'
      tot += cnt == k
  print(tot)


def D():
  pass


def E():
  pass


def F():
  pass

if __name__ == "__main__":
  # A() 
  # B()
  C()
  D()
  E()
  F()

Submission status: Accepted

Solution code:
h, w, k = [int(i) for i in input().split()]
lines = [input() for i in range(h)]
ans = 0
# bit search
for h_1 in range(1 << h):
    for w_1 in range(1 << w):
        black = 0

        for i in range(h):
            for j in range(w):
                if (h_1 >> i) & 1 == 0 and (w_1 >> j) & 1 == 0 and lines[i][j] == '#':
                    black += 1
        if black == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

ans = 0
for ht in itertools.product((0, 1), repeat=H):
    for wt in itertools.product((0, 1), repeat=W):
        black = 0
        for h, w in itertools.product(range(H), range(W)):
            if C[h][w] == '#' and not (ht[h] or wt[w]):
                black += 1
        if black == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
h,w,k=map(int,input().split())
M=[input() for i in range(h)]
ans=0
for m in M:
    ans+=m.count('#')
H=[]
W=[]
for i in range(h):
    H.append(M[i].count('#'))
for i in range(w):
    cnt=0
    for j in range(h):
        if M[j][i]=='#':
            cnt+=1
    W.append(cnt)

a=0
for A in product([0,1],repeat=h):
    for B in product([0,1],repeat=w):
        ANS=ans
        for i in range(h):
            if A[i]==1:
                ANS-=H[i]
        for j in range(w):
            if B[j]==1:
                ANS-=W[j]

        for i in range(h):
            for j in range(w):
                if M[i][j]=='#' and A[i]==1 and B[j]==1:
                    ANS+=1

        if ANS==k:
            a+=1

print(a)

Submission status: Accepted

Solution code:


HWK = input().split()
H = int(HWK[0])
W = int(HWK[1])
K = int(HWK[2])

image = [0]*H*W
# black : 0
# white : 1
# red : 2
for row in range(H):
    c_values = input()
    for col in range(W):
        if c_values[col] == ".":
            image[W*row + col] = 1
        if c_values[col] == "#":
            image[W*row + col] = 0

result = 0
for i in range(2**H):
    for j in range(2**W):
        rows = [int(x) for x in bin(i)[2:]] # 0 : remove, 1 : keep
        rows = max((H - len(rows)), 0)*[0] + rows

        cols = [int(x) for x in bin(j)[2:]]
        cols = max((W - len(cols), 0))*[0] + cols
        # print(cols)
        count_black = 0
        for row in range(H):
            for col in range(W):
                if rows[row] == 0:
                    continue
                if cols[col] == 0:
                    continue
                if image[row*W + col] == 0:
                    count_black += 1
        if count_black == K:
            result += 1



print(result)

Submission status: Accepted

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

import bisect
import copy
import collections
import heapq
import itertools
import math
import numpy as np
from operator import itemgetter
import scipy.misc
import sys

"""
#### 入力例 ####
N, X = map(int, input().split())
x = list(map(int, input().split()))
S = [input() for n in range(N)]
C_ = [list(map(str, input().split())) for n in range(H)]
A = [list(map(int, input().split())) for n in range(H)]

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())
"""


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

def main():
    C_ = np.array(C)
    row_list = collections.deque()
    for n in range(2**H):
        row_list.append([h for h in range(H) if not (n>>h) & 1])
    col_list = collections.deque()
    for n in range(2**W):
        col_list.append([w for w in range(W) if not (n>>w) & 1])
    buf_col_list = list(col_list)
    ans = 0
    while row_list:
        rows = row_list.pop()
        col_list = collections.deque(buf_col_list)
        while col_list:
            cols = col_list.pop()
            cnt = 0
            for h in rows:
                for w in cols:
                    if C_[h,w] == "#":
                        cnt+=1
            if cnt == K:
                ans+=1
    print(ans)
    return
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    h,w,k = LI()
    aa = [[c == '#' for c in S()] for _ in range(h)]

    t = [(i,j) for j in range(w) for i in range(h) if aa[i][j]]

    r = 0
    for ii in range(2**h):
        ia = [((ii >> i) & 1) == 0 for i in range(h)]
        u = [v[1] for v in t if ia[v[0]]]
        if len(u) < k:
            continue

        for jj in range(2**w):
            ja = [((jj >> j) & 1) == 0 for j in range(w)]
            if sum(1 for v in u if ja[v]) == k:
                r += 1

    return r


print(main())

Submission status: Accepted

Solution code:
import copy
h, w, k = map(int,input().split())
dot_map = []
result = 0

for i in range(h):
    tmp_input = list(input())
    dot_map.append(tmp_input)

for h_i in range(2 ** h):
    tmp_dot_map = copy.deepcopy(dot_map)
    for h_degit in range(h):
        if bin(h_i >> h_degit)[-1] == "1":
            tmp_dot_map[h_degit] = list("." * w)

    for w_i in range(2 ** w):
        sharp_counter = 0
        tmp_dot_map_2 = copy.deepcopy(tmp_dot_map)
        for w_degit in range(w):
            if bin(w_i >> w_degit)[-1] == "1":
                for h_draw in range(h):
                    tmp_dot_map_2[h_draw][w_degit] = "."

        for h_s in range(h):
            for w_s in range(w):
                if tmp_dot_map_2[h_s][w_s] == "#":
                        sharp_counter += 1
        if sharp_counter == k:
            result += 1
        # print(tmp_dot_map)
print(result)

Submission status: Accepted

Solution code:
H,W,K = map(int,input().split())
data_list = [list(input()) for i in range(H)]
ans = 0
for i in range(1<<H):
    for j in range(1<<W):
        Black = 0
        for ii in range(H):
            for jj in range(W):
                if(data_list[ii][jj] == "#" and (i>>ii) & 1 == 0 and (j>>jj) & 1 == 0):
                    Black+=1
        if(Black == K):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

h, w, k = map(int, input().split())
rows = [input() for _ in range(h)]
for i in range(2**h):
    for j in range(2**w):
        chk = 0
        for ii in range(h):
            for jj in range(w):
                if (i >> ii) & 1:
                    if (j >>jj) & 1:
                        if rows[ii][jj] == "#":
                            chk += 1
        if chk == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:

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

for R in range(2**H):
    for C in range(2**W):
        blk = 0
        for i in range(H):
            for j in range(W):
                 if ((R >> i) & 1) == 0 and ((C >> j) & 1) == 0 and dot[i][j] == '#':
                    blk += 1
        if blk == K:
            ans += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

h,w,k = LI()
c = [S() for _ in range(h)]

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

print(result)

Submission status: Accepted

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

ans = 0
for ib in range(1<<H):
  for jb in range(1<<W):
    cnt = 0
    for i in range(H):
      for j in range(W):
        #print(i, j, arr[i][j])
        if (ib>>i&1): continue
        if (jb>>j&1): continue
        if arr[i][j] == "#": cnt+=1
    if cnt == K: ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


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

ans = 0
for i in range(2**H):
    for j in range(2**W):
        cnt = 0
        for s in range(H):
            for t in range(W):
                if (i >> s) & 1 and (j >> t) & 1 and C[s][t] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    readline = sys.stdin.buffer.readline
    sys.setrecursionlimit(10 ** 7)

    from itertools import product

    h, w, k = map(int, readline().split())
    c = [readline().rstrip().decode() for _ in range(h)]
    cnt = 0
    for bit_y in product([0, 1], repeat=h):
        for bit_x in product([0, 1], repeat=w):
            memo = 0
            for i, cc in enumerate(c):
                if bit_y[i] == 1:
                    continue
                for j, dc in enumerate(cc):
                    if dc == '#' and bit_x[j] == 0:
                        memo += 1
            if memo == k:
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
sys.setrecursionlimit(int(1e+6))
MOD = int(1e+9) + 7
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

def main():
    H, W, K = i2nn()
    nnn = []
    for _ in range(H):
        s = i2s()
        nn = [1 if c == '#' else 0 for c in s]
        nnn.append(nn)
    def rec(ii, jj, ret):
        if len(ii) < W:
            ret = rec(ii + [0], jj, ret)
            ret = rec(ii + [1], jj, ret)
            return ret
        if len(jj) < H:
            ret = rec(ii, jj + [0], ret)
            ret = rec(ii, jj + [1], ret)
            return ret
        nnn2 = [[n for n in nn] for nn in nnn]
        for k, i in enumerate(ii):
            if i == 1:
                for l in range(H):
                    nnn2[l][k] = 0
        for k, j in enumerate(jj):
            if j == 1:
                for l in range(W):
                    nnn2[k][l] = 0
        n = 0
        for i in range(H):
            for j in range(W):
                if nnn2[i][j] == 1:
                    n += 1
        if n == K:
            ret += 1
        else:
            ret += 0
        return ret
    ret = rec([], [], 0)

    print(ret)

main()

Submission status: Accepted

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

ans = 0
for y_bit in range(2**H):
    for x_bit in range(2**W):
        cnt = 0
        for y in range(H):
            for x in range(W):
                if (y_bit >> y) & 1:
                    continue
                if (x_bit >> x) & 1:
                    continue

                if c[y][x] == '#':
                    cnt += 1
        if cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
dot=[list(input()) for i 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:
                    if dot[ii][jj]=='#':
                        count+=1
        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):
  a = list(str(input()))
  c.append(a)
cnt = 0
blk = 0
for i in range(2 ** h):
  for j in range(2 ** w):
    for k in range(h):
      for l in range(w):
        if ((i >> k) & 1 == 0) and ((j >> l) & 1 == 0) and (c[k][l] == '#'):
          blk += 1
    if blk == K:
      cnt += 1
    blk = 0
print(cnt)

Submission status: Accepted

Solution code:
h, w, K = map(int, input().split())
c = []
for i in range(h):
  a = list(str(input()))
  c.append(a)
cnt = 0
blk = 0
for i in range(2 ** h):
  for j in range(2 ** w):
    for k in range(h):
      for l in range(w):
        if ((i >> k) & 1 == False) and ((j >> l) & 1 == False) and (c[k][l] == '#'):
          blk += 1
    if blk == K:
      cnt += 1
    blk = 0
print(cnt)

Submission status: Accepted

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

rows = []
for _ in range(h):
  row = list(input())
  rows.append(row)

hh = 2 ** h
ww = 2 ** w

result = 0
for i in range(hh):
  for j in range(ww):
    i_bin = format(i, '06b')
    j_bin = format(j, '06b')
    counter = 0
    for k in range(h):
      for l in range(w):
        if i_bin[-k-1] == '0' and j_bin[-l-1] == '0':
          if rows[k][l] == '#':
            counter += 1
    if counter == K:
      # print(i_bin, j_bin)
      result += 1
      
print(result)

Submission status: Accepted

Solution code:
h, w, t = map(int,input().split())
c = []

for i in range(h):
    temp = list(input())
    c.append(temp)

ans = 0

for i in range(2**h):
    list_i = list(bin(i)[2:])
    list_i = [int(x) for x in list_i]
    while len(list_i) != h:
        list_i.insert(0, 0)
    for j in range(2**w):
        temp = 0
        list_j = list(bin(j)[2:])
        list_j = [int(x) for x in list_j]
        while len(list_j) != w:
            list_j.insert(0, 0)
        for k in range(w):
            for l in range(h):
#                print(w-1-k,h-1-l)
                if c[l][k] == '#' and list_i[l] != 1 and list_j[k] != 1:
                    temp += 1
        if temp == t:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
f = [input() for _ 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 (i >> x) & 1 or (j >> y) & 1:
                    continue
                if f[x][y] == "#":
                    black += 1
        if black == k:
            ans += 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

grid = []
for _ in range(h):
  row = input()
  grid.append(row)
  
res = 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 grid[i][j] == '#':
          black += 1
    if black == k:
      res += 1
      
print(res)

Submission status: Accepted

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

base = []
for _ in range(H):
    cs = list(input())
    base.append(cs)

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

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 n in itertools.combinations(list(range(H)),i):
      for m in itertools.combinations(list(range(W)),j):
        count = 0
        for a in n:
          for b in m:
            if(C[a][b]=="#"):
                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

#make binary numbers ranging from 0 to 2**h -1 or 2**w -1
for row in range(2**h):
    for column in range(2**w):
        count = 0
        # Neither ith digit of row nor jth digit of column is 1 and c[i][j] is black.
        for i in range(h):
            for j in range(w):
                if ((row >> i)&1) == 0 and ((column >> j)&1) == 0 and c[i][j] == '#':
                    count += 1
        if count == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import copy

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

c = []
for j in range(h):
    tmpc = input()
    tmpc = [1 if i=='#' else 0 for i in tmpc]
    c.append(tmpc)

#print(c)
cnt = 0
for i in range(2**h):
    for j in range(2**w):
        buc = copy.deepcopy(c)
        sumc = 0
        for k in range(h):
            if i >> k & 1 == 1:
                c[k] = [0] * w    
        for l in range(j):
            if j >> l & 1 == 1:
                for m in range(h):
                    c[m][l] = 0
        for l in range(h):
            sumc += sum(c[l])
        c = copy.deepcopy(buc)
        if sumc == K:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

h, w, k = list(map(int, input().split()))
data = []
for i in range(h):
    data.append(list(input()))
data = np.array(data)

count = 0
for i in range(2 ** h):
    for j in range(2 ** w):
        target = data.copy()
        row = list(bin(i)[2:].zfill(h))
        for p in range(h):
            if row[p] == '1':
                target[p, :] = '.'
        col = list(bin(j)[2:].zfill(w))
        for q in range(w):
            if col[q] == '1':
                target[:, q] = '.'

        if np.count_nonzero(target == '#') == k:
            count += 1
print(count)

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 maskH in range(1 << H):
    for maskW in range(1 << W):
        cnt = 0
        for h in range(H):
            for w in range(W):
                if (maskH >> h) & 1 == 1:
                    continue
                if (maskW >> w) & 1 == 1:
                    continue
                if C[h][w] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

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

ans = 0
# bit 全探索 2^6^2 = 4096
for maskR in range(2 ** H):
    for maskC in range(2 ** W):
        black = 0
        for i in range(H):
            for j in range(W):
                if ((maskR >> i) & 1) == 0 and ((maskC >> j) & 1) == 0 and c[i][j] == '#':
                    black += 1
        if black == K:
            ans += 1
print(ans)

Submission status: Accepted

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

c = []
for i in range(h):
    c.append(input())
ans = 0


#print(c)

'''
入力例1

2 3 2
..#
###

に対して
print(c)
を実行すると
['..#', '###']
と出力される
'''
for i in range(pow(2, h)):
    for j in range(pow(2, w)):
        count = 0
        for p in range(h):
            for q in range(w):
                if ((i & (1 << p)) == 0 and (j & (1 << q)) == 0 and c[p][q] == '#'):
                    count += 1
        
        if (k == count):
            ans += 1

print(ans)