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:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    h, w, k = map(int, input().split())
    c = [input() for i in range(h)]
    ans = []
    def dfs1(i, a):
        if i == h:
            dfs2(0, [0]*w, a)
            return
        dfs1(i+1, a)
        a[i] = 1
        dfs1(i+1, a)
        a[i] = 0

    def dfs2(i, b, a):
        if i == w:
            cnt = 0
            for i in range(h):
                for j in range(w):
                    if a[i] != 0 and b[j] != 0 and c[i][j] == '#':
                        cnt += 1
            if cnt == k:
                ans.append(1)
            return
        dfs2(i+1, b, a)
        b[i] = 1
        dfs2(i+1, b, a)
        b[i] = 0

    dfs1(0, [0] * h)
    print(len(ans))
main()

Submission status: Accepted

Solution code:
from copy import deepcopy
from itertools import product

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
a = 0
for y in product((0, 1), repeat=h):
    for x in product((0, 1), repeat=w):
        d = deepcopy(c)
        for row in range(h):
            if y[row] == 1:
                d[row] = ["r"] * w
        for col in range(w):
            if x[col] == 1:
                for row in range(h):
                    d[row][col] = "r"
        a += sum(row.count("#") for row in d) == k
print(a)

Submission status: Accepted

Solution code:
def examA():
    N = I()
    ans = (10000 - N)%1000
    print(ans)
    return

def examB():
    T = ["AC","WA","TLE","RE"]
    N = I()
    S = [SI()for _ in range(N)]

    ans = [0]*4
    for s in S:
        for i in range(4):
            if s==T[i]:
                ans[i] += 1
                break
    for i in range(4):
        print(T[i]+" x "+str(ans[i]))
    return

def examC():
    H, W, K = LI()
    C = [[""]*W for _ in range(H)]
    for h in range(H):
        S = SI()
        for w in range(W):
            C[h][w] = S[w]
    ans = 0
    #print(C)
    for hi in range(1<<H):
        nowC = deepcopy(C)
        for h in range(H):
            if hi&(1<<h):
                for i in range(W):
                    nowC[h][i] = "R"
        for wi in range(1 << W):
            nowCC = deepcopy(nowC)
            for w in range(W):
                if wi & (1 << w):
                    for i in range(H):
                        nowCC[i][w] = "R"
            cnt = 0
            for h in range(H):
                for w in range(W):
                    if nowCC[h][w] == "#":
                        cnt += 1
            if cnt == K:
                #print(hi, wi, nowCC)
                ans += 1
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

Solution code:
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

#DIV = (10**9) + 7
DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    H,W,K = isRaw()
    cs = [sRaw() for i in range(H)]
    ans =0
    for hc in range(0,2**H):
        for wc in range(0,2**W):
            n= 0
            for h in range(H):
                for w in range(W):
                    if (hc&(1<<h)!=0) and (wc&(1<<w)!=0) and cs[h][w]=="#":
                        n+=1
            if n==K:
                ans+=1
    print(ans)
main()

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    H, W, K = map(int, input().split())
    C = [input().strip("\n") for _ in range(H)]
    ans = 0
    rh = [True] * H
    rw = [True] * W
    for h in range(2 ** H):
        hh = h
        for i in range(H):
            if hh % 2 == 1: rh[i] = False
            else: rh[i] = True
            hh //= 2
        for w in range(2 ** W):
            ww = w
            for j in range(W):
                if ww % 2 == 1: rw[j] = False
                else: rw[j] = True
                ww //= 2
            
            count = 0
            for sh in range(H):
                for sw in range(W):
                    if rh[sh] and rw[sw] and C[sh][sw] == "#": count += 1
            if count == K: ans += 1
    print(ans)


    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations

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

C = np.zeros((H, W))
for i in range(H):
    S = input()
    for j, s in enumerate(S):
        if s == '#':
            C[i, j] = 1
ans = 0
for h in range(H):
    for i in combinations(range(H), h):
        for w in range(W):
            for j in combinations(range(W), w):
                C_ = C.copy()
                for a in i:
                    C_[a, :] = 0
                for b in j:
                    C_[:, b] = 0
                if np.sum(C_) == 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(1<<H):
    for j in range(1<<W):
        cnt = 0
        for k in range(H):
            if i >> k & 1: continue
            for l in range(W):
                if j >> l & 1: continue
                if c[k][l] == "#": cnt += 1
        if cnt == K: ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

H, W, K = rl()
M = []
for i in range(H):
	M.append(rs())

import itertools

def check(b1, b2):
	cnt = 0
	for i in range(H):
		if b1[i]: continue
		for j in range(W):
			if b2[j]: continue
			if M[i][j] == '#':
				cnt += 1
				if cnt > K:
					return False
	if cnt == K:
		return True
	else:
		return False

ans = 0
for b1 in itertools.product([0,1], repeat=H):
	for b2 in itertools.product([0,1], repeat=W):
		if check(b1, b2):
			ans += 1

print(ans)

Submission status: Accepted

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

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

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

print(cnt)

Submission status: Accepted

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

black = 0
for i in range(h):
    for j in range(w):
        if c[i][j] == '#':
            black += 1

ans = 0
for i in range(2 ** h):
    for j in range(2 ** w):
        tmp = 0
        for l in range(h):
            for m in range(w):
                if ((i >> l) & 1) or ((j >> m) & 1):
                    if c[l][m] == '#':
                        tmp += 1

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

print(ans)

Submission status: Accepted

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

A=2**W
B=2**H

M=0
for a in range(A):
    for b in range(B):

        X=0
        for y in range(H):
            for x in range(W):
                if (a>>x)%2==1 and (b>>y)%2==1 and C[y][x]=="#":
                    X+=1
        if X==K:
            M+=1
print(M)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


H, W, K = na()

c_array = [ns() for _ in range(H)]

ans = 0
for i in range(2**(H+W)):
    cnt = 0
    for h in range(H):
        for w in range(W):
            if i & (1 << h) == 0 and i & (1 << (H+w)) == 0 and c_array[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
for i in range(1 << H):
    for j in range(1 << W):
        c = 0
        for h in range(H):
            if i >> h & 1 == 1:
                continue
            for w in range(W):
                if j >> w & 1 == 1:
                    continue
                if C[h][w] == '#':
                    c += 1
        if c == K:
            ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(2**H):
  for j in range(2**W):
    count = 0
    for row in range(H):
      for col in range(W):
        if i >> row & 1 and j >> col & 1:
          if C[row][col] == "#":
            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):
    ci = input()
    c.append(ci)

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    H,W,K = LMIIS()
    table = []
    for i in range(H):
        table.append(list(input()))
    ans = 0
    for i in range(2**H):
        for j in range(2**W):
            count_black = 0
            for x in range(H):
                if 2**x & i:
                    for y in range(W):
                        if 2**y & j and table[x][y] == '#':
                            count_black += 1
            if count_black == K:
                ans += 1

    print(ans)





    
main()

Submission status: Accepted

Solution code:
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    H, W, K = [int(x) for x in input().split()]
    A = [input().strip() for _ in range(H)]

    ans = 0
    for x in range(2 ** H):
        for y in range(2 ** W):
            xset = set()
            yset = set()
            for xx in range(H):
                if x >> xx & 1:
                    xset.add(xx)
            for yy in range(W):
                if y >> yy & 1:
                    yset.add(yy)

            tmp = 0
            for i in range(H):
                if i in xset:
                    continue
                for j in range(W):
                    if j in yset:
                        continue
                    if A[i][j] == "#":
                        tmp += 1

            if tmp == K:
                ans += 1

    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, K, C):
    ans = 0

    for h in range(H+1):
        for w in range(W+1):
            for i in combinations(range(H), r=h):
                i = set(i)
                for j in combinations(range(W), r=w):
                    j = set(j)
                    t = 0
                    for x in range(H):
                        for y in range(W):
                            if x in i or y in j:
                                continue
                            if C[x][y] == '#':
                                t += 1
                    if t == K:
                        ans += 1

    return ans


def main():
    H, W, K = read_int_n()
    C = [read_str() for _ in range(H)]
    print(slv(H, W, K, C))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

#処理内容
def main():
	H, W, K = getlist()
	C = []
	for i in range(H):
		c = list(input())
		C.append(c)

	ans = 0
	for i in range(1 << H):
		for a in range(1 << W):
			bitlistH = []
			bitlistW = []
			for j in range(H):
				if ((i >> j) & 1) == 1:
					#or処理
					bitlistH.append(0)
				else:
					bitlistH.append(1)

			for b in range(W):
				if ((a >> b) & 1) == 1:
					#or処理
					bitlistW.append(0)
				else:
					bitlistW.append(1)

			cnt = 0
			for x in range(H):
				for y in range(W):
					if C[x][y] == "#" and bitlistH[x] == 0 and bitlistW[y] == 0:
						cnt += 1

			if cnt == K:
				ans += 1

	# print(bitlistH)
	# print(bitlistW)

	print(ans)





if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
from copy import deepcopy
h, w, k = map(int, input().split())
c = [list(input()) for i in range(h)]
ans = 0
for i in range(1 << h):
    for j in range(1 << w):
        t = deepcopy(c)
        for x in range(h):
            for y in range(w):
                if (i >> x & 1) or (j >> y & 1):
                    t[x][y] = "."
        p = 0
        for x in range(h):
            for y in range(w):
                if t[x][y] == "#":
                    p += 1
        if p == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    H, W, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    S = tuple(input() for i in range(H)) #改行行列
    cnt=0
    ans=0
    for si in S:
        cnt+=si.count("#")
    for j in range(2**(H+W)):
        c2=0
        for h in range(H):
            for w in range(W):
                if ((j>>(h+W))&1==1 or (j>>(w))&1==1) and S[h][w]=="#":
                    c2+=1
        if cnt-c2==K:
            ans+=1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools


def main():
    H, W, K = list(map(int, input().split(' ')))
    C = [input() for _ in range(H)]
    ans = 0
    for hp in itertools.product([0, 1], repeat=H):
        for wp in itertools.product([0, 1], repeat=W):
            black_cnt = 0
            for h in range(H):
                if hp[h] == 0:
                    continue
                for w in range(W):
                    if wp[w] == 0:
                        continue
                    if C[h][w] == '#':
                        black_cnt += 1
            if black_cnt == K:
                ans += 1
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

hh = list(itertools.product([0,1], repeat=h))
ww = list(itertools.product([0,1], repeat=w))

hbl = [0]*h
wbl = [0]*w
ans = 0
for l in hh:
    for m in ww:
        al = 0
        for i in range(h):
            for j in range(w):
                if l[i] == 0 and m[j] == 0 and c[i][j] == "#":
                    al += 1
                    
        if al == k:
            ans += 1
            
print(ans)

Submission status: Accepted

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


def bit_to_set(bit, n):
    result = set()
    for b in range(n):
        if (1 << b) & bit:
            result.add(b)
    return result


ans = 0
mask = (1 << w) - 1
for b in range(1 << (h + w)):
    p = bit_to_set(b >> w, h)
    q = bit_to_set(b & mask, w)
    tmp = 0
    for i in range(h):
        if i in p:
            continue
        for j in range(w):
            if j in q:
                continue
            if grid[i][j] == '#':
                tmp += 1
    if tmp == k:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    h,w,k = map(int,ipt().split())
    c = [input() for i in range(h)]
    ans = 0
    for i in range(2**h):
        for j in range(2**w):
            num = 0
            for hi in range(h):
                for ji in range(w):
                    if (i >> hi)&1 and (j>>ji)&1 and c[hi][ji] == "#":
                        num += 1
            if num == k:
                ans += 1
    print(ans)        

    return None

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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 i & 1 << k and j & 1 << l and C[k][l] == '#':
                    cnt += 1
        if cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

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

ans = 0
for case_h in range(1 << H):
    tmp = case_h
    flag_y = []
    for _ in range(H):
        flag_y.append(tmp % 2)
        tmp >>= 1
    #
    for case_w in range(1 << W):
        tmp = case_w
        flag_x = []
        for _ in range(W):
            flag_x.append(tmp % 2)
            tmp >>= 1
        #
        cnt = 0
        for y in range(H):
            for x in range(W):
                if flag_y[y] == 0 and flag_x[x] == 0 and c[y][x] == '#':
                    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 i in range(1<<H):
    for j in range(1<<W):
        count = 0
        for k in range(H):
            for l in range(W):
                if c[k][l]=="#" and (i>>k)&1 and (j>>l)&1:
                    count +=1
        if count == K: ans +=1
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

ans = 0
for HH in itertools.product((0,1),repeat=H):
    for WW in itertools.product((0,1),repeat=W):
        a = 0
        for h in range(H):
            for w in range(W):
                if HH[h] and WW[w] and C[h][w] == "#":
                    a += 1
        if a == K:
            ans += 1

print(ans)

Submission status: Accepted

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

C = [list(map(lambda x:x=="#",input())) for _ in [0]*H]

ans = 0

for i in range(1<<H):
    for j in range(1<<W):
        cnt = 0
        for k in range(H):
            if i>>k &1 == 0: continue
            for l in range(W):
                if j>>l &1 ==0: continue
                cnt += int(C[k][l])
        if cnt == K: ans += 1

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline


h,w,k = map(int,readline().split())
s = read().split()

ans = 0

for maskh in range(1<<h):
    for maskw in range(1<<w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if s[i][j] == "#" and (maskh>>i)&1==0 and (maskw>>j)&1==0:
                    cnt += 1
        #print(maskh,maskw,cnt,k)        
        if cnt == k: ans += 1

print(ans)

Submission status: Accepted

Solution code:
def f(i):
    global ans
    if i == h + w:
        cnt = 0
        for j in range(h):
            for l in range(w):
                if s[j] == 0 and s[h + l] == 0 and c[j][l] == "#":
                    cnt += 1
        if cnt == k:
            ans += 1
        return
    s[i] = 1
    f(i + 1)
    s[i] = 0
    f(i + 1)

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

Submission status: Accepted

Solution code:
from itertools import product
H, W, K = map(int, input().split())
M = [input() for _ in range(H)]

ans = 0
for Hs in product(range(2), repeat=H):
    for Ws in product(range(2), repeat=W):
        cnt = 0
        for y in range(H):
            for x in range(W):
                if M[y][x] == '#' and Hs[y] and Ws[x]:
                    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.append(list(input()))

import itertools 
hd = list(itertools.product(range(2), repeat = h))
wd = list(itertools.product(range(2), repeat = w))

ans = 0
for hdata in hd:
    for wdata in wd:
        buf = 0
        for i in range(h):
            for j in range(w):
                if hdata[i]==0 and wdata[j]==0 and c[i][j]=='#':
                    buf += 1
        if buf==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 r in range(1<<H):
    for c in range(1<<W):
        k = 0
        for h in range(H):
            if (r>>h)&1: continue
            for w in range(W):
                if (c>>w)&1: continue
                if C[h][w]=='#': k+=1
        if k==K: ans+=1
        
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

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

ans = 0
for s in product(range(2), repeat=H):
    for t in product(range(2), repeat=W):
        res = [[0]*W for _ in range(H)]

        for i, ri in enumerate(s):
            for j, rj in enumerate(t):
                if ri or rj:
                    res[i][j] = 1
        cnt = 0
        for i in range(H):
            for j in range(W):
                if res[i][j]==0 and l[i][j]=="#":
                    cnt += 1
        ans += (cnt==K)
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1 << h):
    for j in range(1 << w):
        black = 0
        for a in range(h):
            for b in range(w):
                if i >> a & 1 or j >> b & 1:
                    continue
                if c[a][b] == '#': black += 1
        if black == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def isk():
    cnt=0
    for i in range(h):
        if hbit>>i&1:continue
        for j in range(w):
            if wbit>>j&1:continue
            cnt+=cc[i][j]
    return cnt==k

h,w,k=MI()
cc=[[c=="#" for c in SI()] for _ in range(h)]
ans=0
for hbit in range(1<<h):
    for wbit in range(1<<w):
        ans+=isk()
print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
ans = 0
s = [input() for _ in range(h)]
for hi in range(2**h):
	hl = []
	for hj in range(h):
		if (hi >> hj) & 1:
			hl.append(hj)
	tmp = s[:]
	for j in hl:
		tmp[j] = "."*w
	for wi in range(2**w):
		wl = []
		for wj in range(w):
			if (wi >> wj) & 1:
				wl.append(wj)
		cnt = 0
		for i in range(h):
			for j in range(w):
				if j not in wl:
					if tmp[i][j] == "#":
						cnt += 1
		if cnt == k:
			ans += 1
print(ans)

Submission status: Accepted

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

ret = 0
for x in range(1 << W) :
  for y in range(1 << H) :
    s = 0
    for i in range(W) :
      for j in range(H) :
        if x & (1 << i) or y & (1 << j) : continue
        s += c[j][i]
    if s == K :
      ret += 1
      
print(ret)