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  itertools import combinations
from collections import deque
h,w,k = list(map(int, input().split()))
bk = deque()
cr = [[]]*((h+1)*10)
for i in range(1,h+1):
  S = input()
  t = []
  for j in range(1,w+1):
    if S[j-1] == '#':
      bk.append(i*10 + j)
      t.append(i*10 + j)
  cr[i*10] = t
for j in range(1,w+1):
  t = []
  for i in range(1,h+1):
    if (i*10 +j) in bk:t.append(i*10 + j)
  cr[j] = t
  
xy = [i*10 for i in range(1,h+1)]
xy.extend([j for j in range(1,w+1)])
ans = 0

for i in range(len(xy)):
  com = combinations(xy,i)
  n = len(bk)
  for ps in com:
    cnt = set()
    for p in ps:
      [cnt.add(x) for x in cr[p]]
    if n-len(cnt) == k:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
        
    Height, Width, K = map(int, input().split())

    field = []
    ans = 0

    for i in range(Height):
        f = list(input())
        field.append(f)

    for i in range(2 ** Height):
            for k in range(2 ** Width):

                cnt = 0

                for j in range(Height):
                    for l in range(Width):

                        judge_h = (i >> j) & 1
                        judge_w = (k >> l) & 1
                        
                        if (not judge_h and not judge_w):
                            val = field[j][l]
                            if (val == '#'):
                                cnt += 1
                                
                if (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 = [list(str(input())) for i in range(H)]

ans = 0
for i in itertools.product(range(2), repeat=H+W):
    cnt = 0
    for j in itertools.product(range(H), range(W)):
        if i[j[0]]:
            continue
        if i[H+j[1]]:
            continue
        if c[j[0]][j[1]] == '#':
            cnt += 1
    if cnt == K:
        ans += 1

print(ans)

Submission status: Accepted

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

for paint_h in range(2 ** h):
    for paint_w in range(2 ** w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if (paint_h >> i)&1 == 0 and (paint_w >> j)&1 == 0:
                    if board[i][j] == "#":
                        cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

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

for _ in range(H):
    table.append(input())

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

print(ans)

Submission status: Accepted

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

for i in range(h):
    l.append(input())


for ik in range(1<<h):
    for jk in range(1<<w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if ik>>i&1:
                    continue
                if jk>>j&1:
                    continue
                if l[i][j] == "#":
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

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

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

ans = 0

for row_bit in itertools.product(range(2),repeat=h):
    for col_bit in itertools.product(range(2),repeat=w):
        cnt = 0
        for row in range(h):
            for col in range(w):
                if c[row][col] == "#" and (row_bit[row] and col_bit[col]):
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    h,w,k=map(int,readline().split())
    grid=[readline().strip() for _ in range(h)]

    output_h=[]
    for i in range(1<<h):
        tmp=[]
        for j in range(h):
            if(i>>j)&1:
                tmp.append(j)
        output_h.append(tmp)
    
    output_w=[]
    for i in range(1<<w):
        tmp=[]
        for j in range(w):
            if(i>>j)&1:
                tmp.append(j)
        output_w.append(tmp)

    ans=0
    for li_h in output_h:
        for li_w in output_w:
            grid_after=[[True]*w for _ in range(h)]
            
            for i in li_h:
                for j in range(w):
                    grid_after[i][j]=False
            
            for j in li_w:
                for i in range(h):
                    grid_after[i][j]=False

            cnt=0
            for i in range(h):
                for j in range(w):
                    if grid_after[i][j]==True and grid[i][j]=="#":
                        cnt+=1
            
            if cnt==k:
                ans+=1

    print(ans)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
H,W,K=map(int,input().split())
C=[input() for i in range(H)]
B=''.join(C).count('#')
from itertools import product
a=0
for p in product((0,1),repeat=H+W):
    b=B
    for h in range(H):
        for w in range(W):
            if C[h][w]=='#' and (p[h] or p[H+w]):
                b-=1
    if b==K:
        a+=1
print(a)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
c=[list(input()) for i in range(h)]
ans=0
for maskR in range(1<<h):
    for maskC in range(1<<w):
        black=0
        for i in range(h):
            for j in range(w):
                if ((maskR>>i)&1)==0 and ((maskC>>j)&1)==0 and c[i][j]=="#":
                    black+=1
        if black==k:
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
C = []
for h in range(0, H):
    c = str(input())
    C.append(c)
ans = 0
for h in range(0, 2**H):
    for w in range(0, 2**W):
        cnt = 0
        for i in range(0, H):
            for j in range(0, W):
                if ((h >> i) & 1) and ((w >> j) & 1) and (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=[list(input()) for i in range(h)]
ans=0
for maskR in range(1<<h):
    for maskC in range(1<<w):
        black=0
        for i in range(h):
            for j in range(w):
                if ((maskR>>i)&1)==0 and ((maskC>>j)&1)==0 and c[i][j]=='#':
                    black+=1
        if black==k:
            ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h, w, k= (int(x) for x in input().split())
#print(h, w, k)

ans=0
x=['' for i in range(h)]

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

#print(x)
for i in range(2**w):
    w1 = format(i, 'b').zfill(w)
    
    for i in range(2**h):
        h1 = format(i, 'b').zfill(h)
    
        count=0
        for i in range(w):
            for j in range(h):
                if w1[i]=='0' and h1[j]=='0':
                    if x[j][i]=='#':
                        count+=1
        if count==k:
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

H,W,K = map(int,input().split())
lst = []
for i in range(H):
    s = input()
    lst = np.append(lst,[*s])
lst = lst.reshape(H,W)
#print(lst)  

ans = 0
for h in range(1 << H):
    for w in range(1 << W):
        tmp = lst.copy()
        for hh in range(H):
            for ww in range(W):
                if ((h >> hh) & 1) == 1:
                    tmp[-1-hh,:] = "!"
                if ((w >> ww) & 1) == 1:
                    tmp[:,-1-ww] = "!"    
        #print(tmp)    
        if np.count_nonzero(tmp == "#") == K:
            ans += 1
        #print(ans)    
print(ans)

Submission status: Accepted

Solution code:
from copy import deepcopy
h, w, k = map(int, input().split())
C = [[c for c in input()] for i in range(h)]

def subsets(n):
    result = [[]]
    for i in range(n):
        for j in range(len(result)):
            current = result[j]
            result.append(current+[i])
    return result

def countExceptForIndices(rows, columns):
    cnt = 0
    for i in range(h):
        if i in rows:
            continue
        for j in range(w):
            if j in columns:
                continue
            if C[i][j] == "#":
                cnt += 1
    return cnt
redRows = subsets(h)
redColumns = subsets(w)
ans = 0
for r in redRows:
    for j in redColumns:
        if countExceptForIndices(r, j) == 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().rstrip())
ans = 0
for h in range(2**H):
    for w in range(2**W):
        cnt = 0
        for i in range(H):
            for j in range(W):
                if (h>>i)&1 != 1 and (w>>j)&1 != 1 and C[i][j] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Submission status: Accepted

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

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

ans = 0
for row_bit in range(2 ** h):
    for col_bit in range(2 ** w):
        count = 0
        for row in range(h):
            if ((row_bit >> row) & 1):
                continue
            for col in range(w):
                if ((col_bit >> col) & 1):
                    continue
                #print(char_c[row][col], end='')
                if char_c[row][col] == '#':
                    count += 1
            # print()
        if count == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def solve(row, col, l, H, W):
	K = 0
	for x, r in enumerate(row):
		if r == 1:
			for y in range(W):
				if l[x][y] == '#':
					K += 1
					if col[y] == 1:
						K -= 1
	for y, c in enumerate(col):
		if c == 1:
			for x in range(H):
				if l[x][y] == '#':
					K += 1
	return K

H, W, K  = map(int, input().split(" "))
l = []
num_black = 0
for i in range(H):
	l2 = list(input())
	num_black += sum([1 if x == '#' else 0 for x in l2])
	l.append(l2)


answer = 0
for i in range(2 ** (H + W)):
	binary = bin(i)[2:]
	t = [0] * ((H + W) - len(binary)) + [int(x) for x in binary]
	rows = t[:H]
	cols = t[H:]
	k = solve(rows, cols, l, H, W)
	if num_black - k == K:
		answer += 1

print(answer)

Submission status: Accepted

Solution code:
h,w,k = map(int,input().split())
c = [0] * h
for i in range(h):
    c[i] = input()
ans = 0
for si in range(1 << h):
    for sj in range(1 << w):
        cnt = 0
        for i in range(h):
            if si >> i & 1:
                continue
            for j in range(w):
                if sj >> j & 1:
                    continue
                if c[i][j] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
## necessary imports
import sys
input = sys.stdin.readline
# from math import ceil, floor, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1;
    return x;
    
# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp

## gcd function
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b);

## nCr function efficient using Binomial Cofficient
def nCr(n, k): 
    if(k > n - k): 
        k = n - k 
    res = 1
    for i in range(k): 
        res = res * (n - i) 
        res = res / (i + 1) 
    return int(res) 

## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0, hi = None):
    if hi == None:
        hi = len(a);
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x:
            lo = mid+1
        else:
            hi = mid
    return lo

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;


# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n): 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()))
## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################


h, w, k = int_array(); a = [];
for _ in range(h):
    a.append(list(input().strip()));

this = [i + 1 for i in range(h + w)];
perms = [[]];
for i in this:
    new = [];
    for x in perms:
        new.append( x.copy() + [i] );
    perms += new;

ans = 0;
for p in perms:
    mine = [];
    for xx in a:
        mine.append( xx.copy());
    for i in p:
        if i <= h:
            for j in range(w):
                mine[i - 1][j] = '.';
        else:
            for j in range(h):
                mine[j][i - h - 1] = '.';
    cnt = 0;
    for i in range(h):
        for j in range(w):
            if mine[i][j] == '#':
                cnt += 1;
    if cnt == k:
        ans += 1;
print(ans);

Submission status: Accepted

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

ans = 0
for h in range(1<<H):
    for w in range(1<<W):
        cnt = 0
        for i in range(H):
            for j in range(W):
                if (h & (1<<i)) == 0 and (w & (1<<j)) == 0:
                    if A[i][j] == '#':
                        cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
h,w,k=map(int,input().split())
idxs=[]
cols=[0]*w
clis=[]
al=0
k_score=0
def nir(x):
  if x=='#':return 1
  else:return 0
  
for _ in range(h):
  tmp=list(map(nir, list(input())))
  clis.append(tmp)
  idxs.append(sum(tmp))
  al+=sum(tmp)
  for q in range(w):
    cols[q]+=tmp[q]
uu=product((0,1),repeat=h+w)
for bits in uu:
  idd=[]
  coll=[]
  for i in range(h):
    if bits[i]==1:idd.append(i)
  
  for i in range(w):
    if bits[i+h]==1:coll.append(i)
  
  s=al
  if not coll:
    for x in idd:s-=idxs[x]
  elif not idd:
    for y in coll:s-=cols[y]
  else:
    for x in idd:s-=idxs[x]
    for y in coll:s-=cols[y]
    for x in idd:
      for y in coll:
        s+=clis[x][y]
        
  if s==k:k_score+=1
    
print(k_score)

Submission status: Accepted

Solution code:
import itertools

h,w,k=map(int,input().split())
board=[list(input()) for _ in range(h)]
ans=0
for bit_col in itertools.product(range(2),repeat=h):
  for bit_row in itertools.product(range(2),repeat=w):
    cnt=0
    for i in range(h):
      for j in range(w):
        if bit_col[i]==0 and bit_row[j]==0 and board[i][j]=='#':
          cnt+=1
    if cnt==k:
      ans+=1
print(ans)

Submission status: Accepted

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

ans = 0
for h in range(1<<H):
    for w in range(1<<W):
        cnt = 0
        for i in range(H):
            for j in range(W):
                if (h>>i)&1 == 0 and (w>>j)&1 == 0:
                    if Bords[i][j] == "#":
                        cnt += 1
        if cnt == K:
            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:
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:
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
ans = 0
for maskR in range((1 << h) - 1):
    for maskC in range((1 << w) - 1):
        black = 0
        for i in range(h):
            for j in range(w):
                if ((maskR >> i) & 1) == 0 and ((maskC >> j) & 1) == 0:
                    if c[i][j] == '#':
                        black += 1
        if black == k:
            ans += 1
print(ans)

Submission status: Accepted

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

#数えておいただけ。これは落書き
all = 0
for i in c:
  all += i.count("#")

ans = 0
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for hh in range(2 ** h):
  for ww in range(2 ** w):
    #ここで全盤面を再現するわよ
    cnt = 0
    #座標C(h,w)をひとつずつ判定して、countしていくわ
    for i in range(h):
      for j in range(w):
        #bit全探索結果の、1を赤白、0 を黒とするわね
        if (hh >> i) & 1 == 0 and (ww >> j) & 1 == 0:
          if c[i][j] == "#":
            cnt += 1
    if cnt == k:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools as it
H,W,N=map(int,input().split())
c=[list(input()) for t in range(H)]
ans=0
for con in it.product(range(2),repeat=H):
  for row in it.product(range(2),repeat=W):
    count=0
    for h in range(H):
      for w in range(W):
        if c[h][w]=='#' and con[h]==1 and row[w]==1 :
          count+=1
    if count==N:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
import copy
h,w,k=map(int, input().split())
mat = []
for i in range(h):
  s = list(input())
  mat.append(s)
total = 0
for y in range(2**h):
  for x in range(2**w):
    mat2 = copy.deepcopy(mat)
    y_bin = bin(y)[2:].zfill(h)
    x_bin = bin(x)[2:].zfill(w)
    # print(y_bin, x_bin)
    for r in range(len(y_bin)):
      if y_bin[r] == "1":
        for c in range(w):
          mat2[r][c] = "."
    for c in range(len(x_bin)):
      if x_bin[c] == "1":
        for r in range(h):
          mat2[r][c] = "."
    count = 0
    for r in range(h):
      for c in range(w):
        if mat2[r][c] == "#":
          count += 1
          # print(r, c)
    if count == k:
      total += 1
print(total)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
c=[]
for i in range(h):
    c.append(list(input()))
z=0
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            z+=1
ans=0
for i in range(1<<h):
    for j in range(1<<w):
        tmp=0
        for ii in range(h):
            for jj in range(w):
                if (i&(1<<ii) or j&(1<<jj)) and c[ii][jj]=='#':
                    tmp+=1
        if tmp+k==z:
            ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from itertools import product

H, W, K = list(map(int, input().split()))
# 黒なら1
board = [[1 if x == '#' else 0 for x in list(input())] for _ in range(H)]

ans = 0
# 塗らないなら1
for row in product([0, 1], repeat=H):
    for col in product([0, 1], repeat=W):
        # 元が黒でタテヨコ塗らないマスを数える
        blacks = sum([board[h][w] * row[h] * col[w] for h in range(H) for w in range(W)])
        if blacks == 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)]

ans = 0
for bit_y in range(2 ** h):
    for bit_x in range(2 ** w):
        block = 0
        for y in range(h):
            for x in range(w):
                # c[y][x]が元から#じゃない、y,xが赤に塗り替える対象の行と列に選ばれているならカウントしない
                if bit_y >> y & 1 or bit_x >> x & 1 or c[y][x] != '#':
                    continue
                block += 1
        if block == 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 paint_h in range(2**h): #すべての行の塗りつぶし方を2進数で列挙する
    #print(paint_h)    
    for paint_w in range(2**w): #すべての列の塗りつぶし方を2進数で列挙する
        cnt=0
        for i in range(h): #すべてのi行目j列目の要素についてみる
            for j in range(w):
                if (paint_h>>i)&1==0 and (paint_w>>j)&1==0: #各行のi番目のビットと各列のj番目のビットがともに0であればそのマスは塗りつぶされない
                    if board[i][j]=='#': #塗りつぶされないマスが黒マスであれば個数を+1する
                        cnt+=1
        if cnt==k: #塗りつぶされない黒マスの個数がKに等しければ答えを+1する
            ans+=1
print(ans)

Submission status: Accepted

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


ans = 0
n = H + W
for i in range(1<<H):
    for j in range(1<<W):
        cnt = 0
        for I in range(H):
            for J in range(W):
                if((i >> I) & 1):
                    continue
                if((j >> J) & 1):
                    continue
                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())
masu_list = []
ans = 0
for i in range(H):
    masu_list.append(input())
    
for tate in range(2**H):
    for yoko in range(2**W):
        black = 0
        for i in range(H):
            for j in range(W):
                if format(tate>>i,"b")[-1] == "0" and format(yoko>>j,"b")[-1] == "0" and masu_list[i][j] == "#":
                    black += 1
        if black == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
C = []
for _ in range(H): C.append([c for c in input()])
ans = 0
for i in range(1<<H):
    for j in range(1<<W):
        cnt = 0
        for m in range(H):
            for n in range(W):
                if i>>m&1: continue
                if j>>n&1: continue
                if C[m][n] == '#': cnt += 1
        if cnt == K: ans += 1
print(ans)

Submission status: Accepted

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

if __name__ == "__main__":
    Bit_Loop()

Submission status: Accepted

Solution code:
import itertools
import numpy as np
h, w, k = map(int, input().split())

grid = []
row_l = []
column_l = [0 for _ in range(w)]
for i in range(h):
    tmp = list(input())
    grid.append(tmp)
    row_l.append(tmp.count("#"))
    for j in range(w):
        if tmp[j] == "#": column_l[j]+=1

#print(row_l)
#print(column_l)
row_l = np.array(row_l)
column_l = np.array(column_l)
def dup(il,jl):
    sum = 0
    for i in il:
        for j in jl:
            if grid[i][j] == "#": sum+=1
    return sum

to_remove = sum(row_l)-k
ans = 0

for i_n in range(0, h+1):
    for j_n in range(0, w+1):
        for i in itertools.combinations(range(h), i_n):
            for j in itertools.combinations(range(w),j_n):
                if to_remove == sum(row_l[list(i)])+sum(column_l[list(j)])-dup(i,j):
                    ans += 1

print(ans)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
c=[]
for i in range(h):
    cc=input()
    c.append(cc)
ans=0
for i in range(1<<h):
    for j in range(1<<w):
        b=0
        for ii in range(h):
            for jj in range(w):
                if(((i>>ii)&1)==0 and ((j>>jj)&1)==0):
                    if(c[ii][jj]=="#"):b+=1
        if(b==k):ans+=1

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
h,w,k=map(int,input().split())
c=[list(input()) for _ in range(h)]
ans=0
for i in product([0,1],repeat=h):
  for j in product([0,1],repeat=w):
    temp=0
    for m in range(h):
      for n in range(w):
        if i[m]==0 and j[n]==0 and c[m][n]=="#":
          temp+=1
    if temp==k:
      ans+=1
print(ans)

Submission status: Accepted

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

def main():
    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)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import product

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

ans = 0

for bit in product((0, 1), repeat=H):
    for bit2 in product((0, 1), repeat=W):
        k = 0
        for i in range(H):
            for j in range(W):
                if C[i][j] == '#' and bit[i] and bit2[j]:
                    k += 1
        if k == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
H,W,K=map(int,input().split())
li=[input() for _ in range(H)]
ans=0
for ir in range(1<<H):
  for jr in range(1<<W):
    cnt=0
    for i in range(H):
      if (ir>>i)&1:continue
      for j in range(W):
        if (jr>>j)&1:continue
        cnt+=li[i][j]=="#"
    if cnt==K:
      ans+=1
print(ans)