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 itertools

def main():
    H,W,K=map(int,input().split())
    c=[input() for _ in range(H)]
    h=[x for x in range(H)]
    w=[x for x in range(W)]
    ans=0
    for i in range(H):
        for j in range(W):
            for ph in itertools.combinations(h, i):
                for pw in itertools.combinations(w, j):
                    cnt=0
                    for k in range(H):
                        if k in ph: continue
                        for l in range(W):
                            if l in pw: continue
                            if c[k][l]=='#': cnt+=1
                    if cnt==K: ans+=1
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
C = [[True if c == "#" else False for c in input()] for _ in range(H)]


def width_mask():
    ret_mask = [0] * W
    for i in range(2 ** W):
        for j in range(W):
            ret_mask[j] = (i & 1)
            i >>= 1
        yield ret_mask


def height_mask():
    ret_mask = [0] * H
    for i in range(2 ** H):
        for j in range(H):
            ret_mask[j] = (i & 1)
            i >>= 1
        yield ret_mask


ans = 0

for w_mask in width_mask():
    for h_mask in height_mask():
        count = 0
        for i in range(H):
            for j in range(W):
                if w_mask[j] == 1 and h_mask[i] == 1 and C[i][j]:
                    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):
  c.append(input())

ans = 0
for i in range(2 ** h):
  for j in range(2 ** w):
    bin_i = bin(i).replace('0b','').zfill(h)
    bin_j = bin(j).replace('0b','').zfill(w)
    
    count = 0
    for k in range(h):
      for l in range(w):
        if c[k][l] == '#' and bin_i[k] != '1' and bin_j[l] != '1':
          count += 1
          
    if K == count:
      ans += 1
          
print(ans)

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
import copy

h,w,k=nm()

field = []
for y in range(h):
  field.append([_ for _ in input()])

ans=0

s = set()

for yi in range(2**h):
  f1 = copy.deepcopy(field)
  for yj in range(h):
    if ((yi >> yj) & 1):
      f1[yj] = ['*']*w
    for xi in range(2**w):
      f2= copy.deepcopy(f1)
      for xj in range(w):
        if((xi >> xj) & 1):
          for y in range(h):
            f2[y][xj] = '*'
      
      cnt=0
      for y in range(h):
        for x in range(w):
          if f2[y][x] == '#':
            cnt+=1

      if cnt==k:
        ans+=1
        s.add(str(f2))
# print(ans)
print(len(s))

Submission status: Accepted

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

arr = [list(input()) for _ in range(H)]

ans = 0
for row in range(2**H):
  for col in range(2**W):
    count = 0
    for i in range(H):
      if not ((row >> i) & 1): continue
      for j in range(W):
        if not ((col >> j) & 1): continue
        if arr[i][j] == '#':
          count += 1
    if count == K:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from copy import deepcopy
from itertools import combinations


def main():
    h, w, k = map(int, input().split())
    base_table = []
    for i in range(h):
        s = input()
        tmp = []
        for j in s:
            if j == '.':
                tmp.append(0)
            else:
                tmp.append(1)
        base_table.append(tmp)

    tate = [[-1]]
    for n in range(1, h + 1):
        for item in combinations(range(h), n):
            tate.append(list(item))
    yoko = [[-1]]
    for n in range(1, w + 1):
        for item in combinations(range(w), n):
            yoko.append(list(item))

    ans = 0
    for i in tate:
        for j in yoko:
            table = deepcopy(base_table)

            if i[0] != -1:
                for i_idx in i:
                    for s in range(w):
                        table[i_idx][s] = 0
            if j[0] != -1:
                for j_idx in j:
                    for t in range(h):
                        table[t][j_idx] = 0

            cnt = np.array(table).sum()
            if cnt == k:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
c=[input() for i in range(h)]
x=[c[i].count('#') for i in range(h)]
y=[]
s=sum(x)
ans=0
for i in range(w):
    count=0
    for j in range(h):
        count+=(c[j][i]=='#')
    y.append(count)
for i in range(2**(h+w)):
    i='0'*(h+w-len(bin(i)[2:]))+bin(i)[2:]
    count=0
    for j in range(h):
        if i[j]=='1':
            count+=x[j]
    for l in range(w):
        if i[l+h]=='1':
            count+=y[l]
    for j in range(h):
        for l in range(w):
            if i[j]=='1' and i[h+l]=='1':
                if c[j][l]=='#':
                    count-=1
    if s-count==k:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    h, w, k = map(int, input().split())
    masu = [list(input()) for i in range(h)]
    ans = 0
    for i in range(w+1):
        for k1 in itertools.combinations(range(w), i):
            for j in range(h+1):
                for k2 in itertools.combinations(range(h), j):
                    sushi = 0
                    for y in k2:
                        for x in k1:
                            if masu[y][x] == "#":
                                sushi += 1
                    if sushi == k:
                        ans += 1
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
# C - H and V
import itertools

H, W, K = map(int, input().split())
grid = [[''] * W for _ in range(H)]
for i in range(H):
    grid[i] = list(str(input()))

ans = 0
for i in itertools.product((0, 1), repeat=H):
    for j in itertools.product((0,1), repeat=W):
        tmp = 0
        for hi, h in enumerate(i):
            for wj, w in enumerate(j):
                if h == 1 and w == 1 and grid[hi][wj] == '#':
                    tmp += 1
        if tmp == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
m = [input() for _ in range(h)]
crows = [line.count('#') for line in m]
ccols = [0] * w
for j in range(w):
    for i in range(h):
        ccols[j] += (m[i][j] == '#')
sharps = sum(crows)

from itertools import combinations
if sharps < k:
    print(0)
else:
    ans = 0
    for hi in range(2**h):
        for wi in range(2**w):
            combs = sharps
            remh = []
            for hj in range(h):
                if (hi>>hj)&1:
                    remh.append(hj)
                    combs -= crows[hj]
            remw = []
            for wj in range(w):
                if (wi>>wj)&1:
                    remw.append(wj)
                    combs -= ccols[wj]
            
            for hh in remh:
                for ww in remw:
                    if m[hh][ww] == '#':
                        combs += 1
            
            if combs == k:
                ans += 1
    print(ans)

Submission status: Accepted

Solution code:
import itertools
H,W,K=map(int,input().split())
c=[list(input()) for _ in range(H)]
hll=list(itertools.product(range(2),repeat=H))
wll=list(itertools.product(range(2),repeat=W))
ans=0
for hl in hll:
    for wl in wll:
        tc=[]
        for i in c:
            tc.append(i[:])
        for i in range(H):
            if hl[i]==1:
                for j in range(W):
                    tc[i][j]='.'
        for i in range(W):
            if wl[i]==1:
                for j in range(H):
                    tc[j][i]='.'
        t=0
        for i in range(H):
            for j in range(W):
                if tc[i][j]=='#':
                    t+=1
        if t==K:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import copy
h,w,k = map(int,input().split())
grid = [list(input()) for i in range(h)]
# print(grid)
ans = 0
for i in range(2**h):
    for j in range(2**w):
        cnt = 0
        t = copy.deepcopy(grid)
        a = i
        b = j
        while a:
            if a&1:
                for l in range(w):
                    t[cnt][l] = "."
            a = a >> 1
            cnt += 1
        cnt = 0
        while b:
            
            if b&1:
                # print(h,cnt,b,t)
                for l in range(h):
                    t[l][cnt] = "."
            b = b >> 1
            cnt += 1
        cnt = 0
        for l in t:
            cnt += l.count("#")
        if cnt == k:
            ans += 1
            # print(t)
        # if i == 0 and j == 3:
        #     print(t)
print(ans)

Submission status: Accepted

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

c = [[] for _ in range(h)]

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

ans = 0
for mask_y in range(1 << h):
    for mask_x in range(1 << w):
        cnt = 0
        for y in range(h):
            for x in range(w):
                if c[y][x] == "#":
                    cnt += 1
                    if (mask_y >> y) % 2 == 1 or (mask_x >> x) % 2 == 1:
                        cnt -= 1
        if cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq, functools, collections, itertools
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
# import numpy as np
# import scipy


def solve(grid,k):  # fix inputs here
    console(grid)
    grid = [[1 if x == "#" else 0 for x in row] for row in grid]
    console("----- solving ------")
    console(grid)

    res = 0

    for arr in itertools.product([0,1], repeat=len(grid)+len(grid[0])):
        cnt = 0
        for i,row in enumerate(grid):
            for j,cell in enumerate(row):
                if arr[i] == 0 and arr[-j-1] == 0 and cell == 1:
                    cnt += 1
        if cnt == k:
            res += 1
        # print(arr, res, cnt)
    
    return res


def console(*args):  # the judge will not read these print statement
    print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return


for case_num in [1]:
    # read line as a string
    # strr = input()

    # read line as an integer
    # k = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    nrows,_,k = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    grid = []
    for _ in range(nrows):
        grid.append(input())

    res = solve(grid,k)  # please change
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
    print(res)

Submission status: Accepted

Solution code:
# import time
# t1=time.time()
def LI():return list(map(int,input().split()))
# def I(): return int(input())
# from collections import deque, Counter, defaultdict
# from heapq import heappop, heappush
# from pprint import pprint
# import numpy as np
import itertools
nums = [0,1]

h,w,k=LI()
c=[]
for _ in range(h):
    c.append(list(input()))

f=0
for i in range(h):
    for j in range(w):
        if c[i][j]=="#":
            f+=1
# print(f)

ans=0
for ii in list(itertools.product(nums,repeat=h)):
    for jj in list(itertools.product(nums,repeat=w)):
        # print(ii,jj)
        cnt=0
        for i,ci in enumerate(ii):
            for j,cj in enumerate(jj):
                if ci==1 or cj==1:
                    if c[i][j]=="#":
                        cnt+=1
        if cnt==f-k:
            # print(ii,jj)
            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(2**H):
  for j in range(2**W):
    cnt=0
    for ii in range(H):
      for jj in range(W):
        if (i>>ii)%2==0 or (j>>jj)%2==0 or F[ii][jj]==".":
          continue
        cnt+=1
    if cnt==K:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
from copy import deepcopy

def solve(bit1):
    L1 = deepcopy(grid)
    ret = 0
    for i in range(h):
        if bit1[i]:
            L1[i] = ['x'] * w
    for i in range(1 << w):
        bit2 = [0] * w
        for j in range(w):
            if i >> j & 1:
                bit2[j] = 1
        cnt = 0
        L2 = deepcopy(L1)
        for l in range(w):
            if bit2[l]:
                for m in range(h):
                    L2[m][l] = 'x'
        for i in range(h):
            for j in range(w):
                if L2[i][j] == '#':
                    cnt += 1
        if cnt == k:
            ret += 1
    return ret

h, w, k = map(int, input().split())
grid = list(list(input()) for _ in range(h))
ans = 0
for i in range(1 << h):
    bit1 = [0] * h
    for j in range(h):
        if i >> j & 1:
            bit1[j] = 1
    ans += solve(bit1)
print(ans)

Submission status: Accepted

Solution code:
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7
sys.setrecursionlimit(10**4)
# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
 
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

# @bootstrap
def backtrack(cur,cnt):
    if cur == tot:
        tcnt = 0
        row = flag[:n]
        col = flag[n:n+m]
        for i in range(n):
            for j in range(m):
                if row[i] == 1 or col[j] == 1:
                    continue
                elif lis[i][j] == '#':
                    tcnt+=1
        if tcnt == k:
            cnt[0]+=1
        return 
         
    backtrack(cur+1,cnt)
    flag[cur] = 0
    backtrack(cur+1,cnt)
    flag[cur] = 1
     

n,m,k = Ri()
lis = []
for i in range(n):
    s = ri()
    lis.append(s)

cnt = [0]
flag = [1]*(n+m)
tot = n+m
backtrack(0,cnt)
print(cnt[0])

Submission status: Accepted

Solution code:
import itertools
H,W,K = map(int,input().split())
c = [input() for _ in range(H)]
res = 0
for ls1 in itertools.product([0,1], repeat=H):
    for ls2 in itertools.product([0,1], repeat=W):
        tmp = 0
        for h in range(H):
            for w in range(W):
                if c[h][w] == '#' and ls1[h] == 0 and ls2[w] == 0:
                    tmp += 1
        if tmp==K:
            res += 1
print(res)

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt = 0
for h in range(2**H):
    h_list = []
    for _ in range(H):
        h_list.append(h%2)
        h //= 2
    for w in range(2**W):
        w_list = []
        for _ in range(W):
            w_list.append(w%2)
            w //= 2
        tmp = []
        
        for i in range(H):
            for j in range(W):
                if h_list[i] == 0 and w_list[j] == 0:
                    tmp.append(c[i][j])
        
        tmp = Counter(tmp)
        if tmp['#'] == K:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import itertools

h,w,k = map(int,input().split())
ab = []
for _ in range(h):
    s=list(input())
    ab.append(s)

tate = []
yoko = []
 
for i in range(h):
    tate.append(i)

for i in range(w):
    yoko.append(i)

ans = 0

for i in range(h+1):
    for j in range(w+1):
        for v in itertools.combinations(tate, i):
            for vv in itertools.combinations(yoko, j):
                memo = 0
                for tt in range(h):
                    if tt in v:
                        continue
                    for yy in range(w):
                        if yy in vv:
                            continue
                        if ab[tt][yy] == '#':
                            memo += 1
                if memo == k:
                    ans += 1
print(ans)

Submission status: Accepted

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

C = [list(input()) for i in range(H)]
# cumsumH = []
# cumsumW = []

# for h in range(H):
#     cumsumH += [sum([c == '#' for c in C[h]])]
# for w in range(W):
#     cumsumW += [sum([C[i][w] == '#' for i in range(H)])]
ans = 0
# print(cumsumH)
# print(cumsumW)

for h in range(2**H):
    for w in range(2**W):
        CC = copy.deepcopy(C)
        tmp = 0
        for i in range(H):
            if (h >> i) & 1:
                for j in range(W):
                    CC[i][j] = 'R'
        for i in range(W):
            if (w >> i) & 1:
                for j in range(H):
                    CC[j][i] = 'R'
        for i in range(H):
            for j in range(W):
                if CC[i][j] == '#':
                    tmp += 1
        if tmp == K:
            ans += 1
            # print(h, w)

print(ans)

Submission status: Accepted

Solution code:
# Problem C - H and V

# input
H, W, K = map(int, input().split())
board = [['']*W for i in range(H)]
for i in range(H):
    s = list(input())
    for j in range(W):
        board[i][j] = s[j]

# pattern
h_pattern = []
w_pattern = []
for i in range(2**H):
    p = [0]*H
    for j in range(H):
        if (i>>j)&1==1:
            p[j] = 1
    h_pattern.append(p)
for i in range(2**W):
    p = [0]*W
    for j in range(W):
        if (i>>j)&1==1:
            p[j] = 1
    w_pattern.append(p)

# initialization
ans = 0


# bit search
for h_p in h_pattern:
    for w_p in w_pattern:
        # 0が塗ってない場合
        tmp = 0
        for i in range(H):
            if h_p[i]==0:
                for j in range(W):
                    if w_p[j]==0 and board[i][j]=='#':
                        tmp += 1
        # check
        if tmp==K:
            ans += 1

# output
print(ans)

Submission status: Accepted

Solution code:
n, m, k = map(int, input().split())
mat = [list(input()) for _ in range(n)]
t = 0
for b in range(1<<(n+m)):
    c = 0
    for i in range(n):
        for j in range(m):
            if mat[i][j] == "#" and not ((1<<i & b) or (1<<(j+n) & b)):
                c += 1
    if c == k:
        t += 1
print(t)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
import copy
from itertools import combinations
H,W,K = [int(x) for x in stdin.readline().rstrip().split()]
C = []
for i in range(H):
    c = list(input())
    C.append(c)

ans = 0

for h in range(0,H+1):
    for w in range(0,W+1):
        for i in combinations(range(0,H),h):
            for j in combinations(range(0,W),w):
                tmp = copy.deepcopy(C)
                tmp = np.array(tmp)
                for k in i:
                    tmp[k,] = "."
                for l in j:
                    tmp[:,l] = "."
                if np.sum(tmp == "#") == K:
                    ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(2**h):
    for j in range(2**w):
        cnt = 0
        x = format(i, "b").zfill(h)
        y = format(j, "b").zfill(w)
        for xi in range(h):
            for yi in range(w):
                if x[xi] == "0" and y[yi] == "0":
                    if c[xi][yi] == "#":
                        cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(2**H):
    for j in range(2**W):
        c = 0
        for p in range(H):
            for q in range(W):
                if T[p][q] == "#":
                    if (i>>p) & 1:
                        if (j>>q) & 1:
                            c += 1
        if c == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

H, W, K = ri_()
c = [list(rs()) for _ in range(H)]
ans = 0
for bit in range(1<<H):
    for bitr in range(1<<W):
        cnt = 0
        for i in range(H):
            for j in range(W):
                if not (bit & (1 << i)):
                    if not (bitr & (1 << j)):
                        if c[i][j] == '#':
                            cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Submission status: Accepted

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


ans=0
for x2 in range(2**(h+w)):
  x=format(x2, 'b')
  x=(h+w-len(x))*'0'+x
  co=0
  for i in range(h):
    if x[i]=='0':
      for j in range(w):
        if x[h+j]=='0' and c[i][j]=='#':
          co+=1
  if co==k:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**6)

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

c = [0]*w
r = [0]*h

def count(hc, wc):
    ans = 0
    for i in range(h):
        for j in range(w):
            if l[i][j] == "#" and not ((hc >> i)%2 == 1 or (wc >> j)%2 == 1):
                ans += 1
    return ans

ans = 0
for i in range(2**h):
    for j in range(2**w):
        if count(i, j) == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools

H,W,K = [int(i) for i in input().split()]
c = []
for _ in range(H):
    a = list(input())
    a = [1 if i == "#" else 0 for i in a ]
    c.append(a)
ans = 0
for i in range(H+1):
    for j in range(W+1):
        for A in itertools.combinations(range(H), i):
            for B in itertools.combinations(range(W),j):
                s = 0
                for k in A:
                    for l in B:
                        s += c[k][l]
                if s == K:
                    ans += 1
print(ans)

Submission status: Accepted

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


def solve(H, W, K, C):
    cnt = 0
    L1 = list(product([True, False], repeat=H))
    L2 = list(product([True, False], repeat=W))
    for l1 in L1:
        for l2 in L2:
            num = 0
            for i in range(H):
                if not l1[i]:
                    continue
                for j in range(W):
                    if not l2[j]:
                        continue
                    num += C[i][j]
            if num == K:
                cnt += 1
    print(cnt)
    return

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))
    W = int(next(tokens))
    K = int(next(tokens))
    C = [[0 for _ in range(W)] for _ in range(H)]
    for i in range(H):
        col = next(tokens)
        for j in range(W):
            C[i][j] = 1 if col[j] == "#" else 0
    solve(H, W, K, C)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import copy
import itertools

import numpy as np

H, W, K = map(int, input().split())
C = np.array([list(input()) for _ in range(H)])
F = np.zeros([H, W], dtype=np.int64)

for i in range(H):
    for j in range(W):
        if C[i][j] == "#":
            F[i][j] = 1


cnt = 0
for i in itertools.product(range(2), repeat=H):
    f = copy.deepcopy(F)

    ii = np.arange(H)[np.array(i) == 1]

    f[ii] = 0

    for j in itertools.product(range(2), repeat=W):
        jj = np.arange(W)[np.array(j) == 1]
        ff = copy.deepcopy(f)
        ff[:, jj] = 0
        if np.sum(ff) == K:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import itertools as it
# import numpy as np

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H, W, K = map(int,input().split(" "))
    S = [[int(_) for _ in input().replace("#","1").replace(".","0")] for _ in range(H)]
    # S = np.array(S)

    kw = []
    for i in range(1,W+1):
        kw += list(it.combinations(range(W),i))
    kh = []
    for i in range(1,H+1):
        kh += list(it.combinations(range(H),i))

    def slice(w,h):
        r = 0
        for w_ in w:
            for h_ in h:
                r += S[h_][w_]
        return r

    ans=0
    for iw in kw:
        for ih in kh:
            if slice(iw,ih) == K: ans+=1
                
    print(ans)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

H, W, K = [int(s) for s in input().split()]

c_mat = []

for _ in range(H):
    row = input()
    cs = []
    
    for j in range(W):
        if row[j] == ".":
            cs.append(0)
        else:
            cs.append(1)


    c_mat.append(cs)

c_np = np.array(c_mat, dtype=np.int)


count = 0

# 色を塗る
for h in range(2**H):
    for w in range(2**W):
        c_np_tmp = np.copy(c_np)

        for i in range(H):
            if (h >> i) % 2 == 1:
                c_np_tmp[i, :] = 0

        for j in range(W):
            if (w >> j) % 2 == 1:
                c_np_tmp[:, j] = 0

        if c_np_tmp.sum() == K:
            count += 1

print(count)

Submission status: Accepted

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

c = [input() for _ in range(H)]

ans = 0
for h in range(2**H):
    h = "{:06b}".format(h)[-H:]
    for w in range(2**W):
        w = "{:06b}".format(w)[-W:]

        cnt = 0
        for i in range(len(h)):
            for j in range(len(w)):
                if h[i] == "0" and w[j] == "0":
                    if c[i][j] == "#":
                        cnt += 1
        
        if cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8
from copy import deepcopy

H, W, K = map(int, input().split(' '))
C = []
ans = 0

for _ in range(H):
    row = input()
    C.append([el for el in row])

for h in range(2**H):
    for w in range(2**W):
        h_red = str(bin(h)).lstrip("0b").zfill(H)
        w_red = str(bin(w)).lstrip("0b").zfill(W)
        table = deepcopy(C)
        num_black = 0
        for i, f in enumerate(h_red):
            if f == '1':
                table[i] = ['r' for _ in range(W)]
        for i, f in enumerate(w_red):
            if f == '1':
                for s in table:
                    s[i] = 'r'
        for s in table:
            num_black += s.count('#')
        if num_black == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import copy
h,w,k=map(int,input().split())
c=[None]*h
for i in range(h):
  c[i]=list(input())
ans=0
for i1 in range(2**h):
  for i2 in range(2**w):
    tmp=copy.deepcopy(c)
    b=0
    for j1 in range(h):
      for j2 in range(w):
      	if not ((i1 >> j1) & 1) and not ((i2 >> j2) & 1):
          if c[j1][j2]=='#':
            b+=1
    if b==k:
      ans+=1
print(ans)