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
import decimal
import math
import collections
import sys
input = sys.stdin.readline
import copy

# S=(input())
# N=int(input())
# N,K=map(int,input().split())
# ListA=list(map(int,input().split()))
# ListA.sort()#reverse=True)



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

    s=[list(map(str,list(input()))) for i in range(H)]

    lisH= [num for num in range(1,H+1)]
    resultH = []
    for n in range(1,len(lisH)+1):
        for conb in itertools.combinations(lisH, n):
            resultH.append(list(conb))
    resultH.append([0])

    lisW= [num for num in range(1,W+1)]
    resultW = []
    for n in range(1,len(lisW)+1):
        for conb in itertools.combinations(lisW, n):
            resultW.append(list(conb))
    resultW.append([0])

    ans=0
    for h in range(len(resultH)):
        paintH=resultH[h]
        for w in range(len(resultW)):
            paintW=resultW[w]
            tmp=copy.deepcopy(s)
            for delH in paintH:
                if(delH!=0):
                    for i in range(W):
                        tmp[delH-1][i]="."
            for delW in paintW:
                if(delW!=0):
                    for i in range(H):
                        tmp[i][delW-1]="."  
            Cnt=0
            for i in range(H):
                Cnt+=tmp[i].count("#")
            if(Cnt==K):
                ans+=1
            

    print(ans) 



resolve()

Submission status: Accepted

Solution code:
h, w, K = map(int, input().split())
a = []
g = 0
for i in range(h):
    a.append(input())
for i in range(2**h):
    b = h-1
    c = []
    while i > 0:
        if i%2 == 1:
            c.append(b)
        i //= 2
        b -= 1
    for j in range(2**w):
        d = w-1
        e = []
        while j > 0:
            if j%2 == 1:
                e.append(d)
            j //= 2
            d -= 1
        f = 0
        for k in c:
            for l in e:
                if a[k][l] == "#":
                    f += 1
        if f == K:
            g += 1
print(g)

Submission status: Accepted

Solution code:
def dfs4(bi, a):
    res = 0
    for j in range(len(a)):
        for i in range(W):
            if bi[i] == 1 and a[j][i] == '#':
                res += 1
    if res == K:
        ans[0] += 1
    return

def dfs3(bi, a):
    if len(bi) == W:
        return dfs4(bi, a)
    for i in range(2):
        bi.append(i)
        dfs3(bi, a)
        bi.pop()
    return

def dfs2(bits):
    a = []
    for i in range(H):
        if bits[i] == 1:
            a.append(maze[i])
    dfs3([], a)
    #print(a)
    return

def dfs(bits):
    if len(bits) == H:
        return dfs2(bits)
    for i in range(2):
        bits.append(i)
        dfs(bits)
        bits.pop()
    return

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

ans = [0]
dfs([])
print(ans[0])

Submission status: Accepted

Solution code:
from itertools import combinations
from copy import deepcopy

def readinput():
    h,w,k=list(map(int,input().split()))
    c=[]
    for _ in range(h):
        l=list(input())
        c.append(l)
    return h,w,k,c

def main(h,w,k,c):
    gyo=[]
    for i in range(1,h+1):
        for cmb in combinations(range(1,h+1),i):
            gyo.append(cmb)
    gyo.append(())

    retsu=[]
    for i in range(1,w+1):
        for cmb in combinations(range(1,w+1),i):
            retsu.append(cmb)
    retsu.append(())

    ans=0
    for g in gyo:
        for r in retsu:
            cc=deepcopy(c)
            #print(cc)
            #print(g,r)
            
            for i in g:
                for j in range(1,w+1):
                    cc[i-1][j-1]='*'

            for j in r:
                for i in range(1,h+1):
                    cc[i-1][j-1]='*'
            #print(cc)
            count=0
            for i in range(1,h+1):
                for j in range(1,w+1):
                    if cc[i-1][j-1]=='#':
                        count+=1
            if count==k:
                ans+=1

    return ans

if __name__=='__main__':
    h,w,k,c=readinput()
    ans=main(h,w,k,c)
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import copy
H,W,K = map(int,input().split())
C = []
for i in range(H):
    array = []
    temp = input()
    #白：０　黒：１
    array = [1 if i == '#' else 0 for i in temp]
    C.append(array)

C = np.array(C)
ans = 0
for i in range(2 ** H):
    for j in range(2 ** W):
        temp = copy.deepcopy(C)
        temp = temp.T
        for k in range(W):
            if((j>>k)&1):
                #j列目を削除する
                temp[k] = [0 for l in range(H)]
        temp = temp.T
        for k in range(H):
            if((i>>k)&1):
                #i行目を削除する
                temp[k] = [0 for m in range(W)]
    
        if sum(temp.flatten()) == K :
            ans = ans+1

print(ans)

Submission status: Accepted

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc173/abc173_c
import sys
import itertools
import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    H, W, K = i2nn()
    c = [None] * H
    for i in range(H):
        c[i] = [int(s == '#') for s in i2s()]
    ans = 0
    p1 = np.array(c)
    for h, w in itertools.product(range(H), range(W)):
        for row in itertools.combinations(range(H), h):
            p2 = p1.copy()
            for i in row:
                p2[i, :] = 0
            for col in itertools.combinations(range(W), w):
                p3 = p2.copy()
                for j in col:
                    p3[:, j] = 0
                if (p3.sum() == K):
                    ans += 1
    print(ans)
                
    return

main()

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
table = []
for i in range(H):
    table.append(str(input()))
outer = 2**H
inner = 2**W
gyouketa  = '0'+str(H)+'b'
retuketa  = '0'+str(W)+'b'
count = 0
ans = 0
for i in range(outer):
    for j in range(inner):
        gyou = format(i, gyouketa)
        retu = format(j, retuketa)
        for h in range(H):
            if gyou[h] == '0':
                for w in range(W):
                    if retu[w] == '0' and table[h][w] == '#':
                        count += 1
        if count == K:
            ans += 1
        count = 0
print(ans)

Submission status: Accepted

Solution code:
import copy
from itertools import combinations

def count_sharp(a):
	count = 0
	for i in range(len(a)):
		for j in range(len(a[0])):
			if a[i][j] == '#':
				count += 1
	return count

H,W,K = map(int, input().split())
h = [x for x in range(H)]
w = [x for x in range(W)]

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

h_sub = list()
for i in range(len(h) + 1):
	for con in combinations(h, i):
		h_sub.append(con)

w_sub = list()
for i in range(len(w) + 1):
	for con in combinations(w, i):
		w_sub.append(con)

count = 0
for h in h_sub:
	for w in w_sub:
		cc = copy.deepcopy(c)
		if len(h) != 0:
			for hh in h:
				width = len(cc[0])
				for j in range(width): cc[hh][j] = 'r'
		if len(w) != 0:
			for ww in w:
				height = len(cc)
				for i in range(height):
					cc[i][ww] = 'r'
		if count_sharp(cc) == K:
			count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np
H,W,K = (int(x) for x in input().split())
Tile = np.zeros((H,W),dtype=bool)
Count = 0
for T in range(0,H):
    Tile[T,:] = np.array([True if I=='#' else False for I in list(input())])
for TT in range(0,pow(2,H)):
    DrawG = list(int(x) for x in list(('{:0'+str(H)+'b}').format(TT,'b')))
    GTile = np.copy(Tile)
    for TH in range(0,H):
        if DrawG[TH]==1:
            GTile[TH,:] = False
    for TTT in range(0,pow(2,W)):
        WTile = np.copy(GTile)
        DrawL = list(int(x) for x in list(('{:0'+str(W)+'b}').format(TTT,'b')))
        for TTW in range(0,W):
            if DrawL[TTW]==1:
                WTile[:,TTW] = False
        if np.sum(WTile)==K:
            Count += 1
print(Count)

Submission status: Accepted

Solution code:
H,W,K = map(int,input().split())
L = []
for _ in range(H):
    l = list(input())
    L.append(l)
import copy
ans =0
for x in range(2 ** H):
    for y in range(2 ** W):
        c = copy.deepcopy(L)

        for i in range(H):
            if x & (1 << i):
                for yoko in range(W):
                    c[i][yoko] = '.'
        for j in range(W):
            if y & (1 << j):
                for tate in range(H):
                    c[tate][j] = '.'
        #count
        cnt = 0
        for i in range(H):
            for j in range(W):
                if c[i][j] == '#': cnt += 1
        if cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

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

rst = 0
for i in range(pow(2, h)):
    h_mask = np.array(list(map(lambda x: x == "0", ("000000" + bin(i)[2:])[-h:])))
    _c = c[h_mask].T
    for j in range(pow(2, w)):
        w_mask = np.array(list(map(lambda x: x == "0", ("000000" + bin(j)[2:])[-w:])))
        if len(_c) == 0:
            count = 0
        else:
            __c = _c[w_mask]
            count = np.count_nonzero(__c == '#')
        if k == count:
            rst += 1

print(rst)

Submission status: Accepted

Solution code:
H, W, K = list(map(int, input().split()))
import numpy as np
a = np.full((H, W), '.')
for i in range(H):
    a[i] = list(input())



def check(a, p_r, p_c):
    a2 = a.copy()
    for i, s in enumerate(p_r):
        if s=='1':
            a2[i] = 'r'
    for i, s in enumerate(p_c):
        if s=='1':
            a2[:,i] = 'r'

    return np.sum(a2=='#')



result = 0
n = H+W
for i in range(2**n):
    pattern = format(i, '0%db'%n)
    p_r = pattern[:H]
    p_c = pattern[H:]
    if check(a, p_r, p_c) == K:
        result += 1

print(result)

Submission status: Accepted

Solution code:
import itertools

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

if K == H*W:
    print(1)
    exit()

b = 0
for i in range(H):
    for j in range(W):
        if field[i][j] == "#":
            b += 1

r = [i for i in range(H)]
c = [i for i in range(W)]

r_comb = []
for h in range(H):
    for v in itertools.combinations(r,h):
        r_comb.append(v)
c_comb = []
for w in range(W):
    for v in itertools.combinations(c,w):
        c_comb.append(v)      

ans = 0
for R in r_comb:
    for C in c_comb:
        tmp = b

        #選んだ行に対する処理
        for h in range(H):
            if h in R:
                tmp -= field[h].count("#")

        #選んだ列に対する処理
        for h in range(H):
            if h not in R:
                for w in range(W):
                    if w in C and field[h][w] == "#":
                        tmp -= 1
    
        if tmp == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools
import copy
h, w, k = (int(x) for x in input().split())
count=0
c =[[]for i in range(h)]
for i in range(h):
	c[i]=input()
	
for i in range(h):
	for j in range(w):
		if c[i][j]=="#":
			count+=1
ans = 0
need = count-k

for i in itertools.product([0,1], repeat=h):
	need1 = need
	c_2 = copy.copy(c)
	for j in range(h):
		if i[j]==1:
			for k in range(w):
				if c_2[j][k]=="#":
					need1-=1
			list = ["."]*w
			c_2[j]="".join(list)
					
					
	for j in itertools.product([0,1], repeat=w):
		need2=need1
		for k in range(w):
			if j[k]==1:
				for l in range(h):
					if c_2[l][k]=="#":
						need2-=1
		if need2==0:
			ans+=1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
h,w,k = map(int, input().split())
a =[]
for i in range(h):
  a.append(input().split())
f=list(product([0,1], repeat=h))
f2=list(product([0,1], repeat=w))
b=0
su=0
for i in f:
    for j in f2:
        for i2 in range(h):
            for j2 in range(w):
                if i[i2]==0 and j[j2]==0:
                    if a[i2][0][j2]=="#":
                        b+=1
        if b==k:
            su+=1
        b=0
print(su)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
cc = [list(input()) for _ in range(H)]
c = [c[:] for c in [[''] * W] * H]
ans = 0
for h in range(2**H):
    for w in range(2**W):
        for i in range(H):
            for j in range(W):
                 c[i][j] = cc[i][j]            
        for i in range(H):
            if ((h >> i) & 1):
                for jj in range(W):
                    c[i][jj] = "!"
        for j in range(W):
            if ((w >> j) & 1):
                for ii in range(H):
                    c[ii][j] = "!"
        black = 0
        for i in range(H):
            for j in range(W):
                 if c[i][j] == '#':
                    black += 1
        if black == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import copy

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


for i in range(H):
    tm=input()
    for j in range(W):
        S[i][j]=tm[j]



anscount=0

for i in range(2 **(H+W)):
    tmp=copy.deepcopy(S)
    for j in range(H+W):
        if ((i >> j) & 1):
            #print(i,j)のjbitがONの意味
            if j<H:
                for k in range(W):
                    tmp[j][k]="."
            else:
                for k in range(H):
                    tmp[k][j-H]="."
    tmpcount=0
    #print(tmp)
    for k in range(H):
        for l in range(W):
            if tmp[k][l]=="#":
                tmpcount+=1
    if tmpcount==K:
        anscount+=1
        
print(anscount)

Submission status: Accepted

Solution code:
import copy
H,W,K = map(int,input().split())
c = [list(str(input())) for _ in range(H)]
ans = 0
count = 0
for i in range(H):
  count += c[i].count("#")
for h in range(2**H):
  PH = bin(h)[2:].zfill(H)
  for w in range(2**W):
    PW = bin(w)[2:].zfill(W)
    # print(PH,PW)
    count1 = copy.copy(count)
    check = [[0 for _ in range(W)]for _ in range(H)]
    for i in range(H):
      for j in range(W):
        if PH[i] == "1" or PW[j] == "1":
          if c[i][j] == "#" and check[i][j] == 0:
            count1 -= 1
            check[i][j] = 1
    if count1 == K:
      ans += 1
print(ans)

Submission status: Accepted

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

tate=[]
yoko=[]
for i in range(1<<h):
  t=[]
  for j in range(h):
    if i&(1<<j):
      t.append(1)
    else:
      t.append(0)
  tate.append(t)
for i in range(1<<w):
  t=[]
  for j in range(w):
    if i&(1<<j):
      t.append(1)
    else:
      t.append(0)
  yoko.append(t)
ans=0
# print(tate)
# print(yoko)
for i in range(len(tate)):
  for j in range(len(yoko)):
    tt=[]
    tt=deepcopy(c)
    t_cnt=0
    t_tate=tate[i]
    t_yoko=yoko[j]
    # print(t_tate)
    # print(t_yoko)
    for a in range(len(t_tate)):
      if t_tate[a]==1:
        for b in range(w):
          tt[a][b]="@"
    for a in range(len(t_yoko)):
      if t_yoko[a]==1:
        for b in range(h):
          tt[b][a]="@"
    for a in range(h):
      for b in range(w):
        if tt[a][b]=="#":
          t_cnt+=1
    # print(tt)  
    if t_cnt==k:
      ans+=1
print(ans)


# h,w,k=map(int,input().split())
# c=[list(input()) for i in range(h)]
# ans=0
# tt=c[:]
# for i in range(1<<h):
#   t=tt
#   t_cnt=0
#   for a in range(h):
#     if i%(1<<a):
#       for b in range(w):
#         t[a][b]="@"
#   for j in range(1<<w):
#     for a in range(w):
#       if j%(1<<a):
#         for b in range(h):
#           t[b][a]="@"
#   for c in range(h):
#     for d in range(w):
#       if t[c][d]=="#":
#         t_cnt+=1
#   if t_cnt==k:
#     ans+=1
# print(ans)

Submission status: Accepted

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

bith=[]
bitw=[]
for a in range(h):
    bith.append(0)

for b in range(w):
    bitw.append(0)

p=0
while(1):
    s=0
    for a in range(h):
        if bith[a]==0:
            for b in range(w):
                if bitw[b]==0:
                    if c[a][b]=='#':
                        s=s+1

    if s==k:
        p=p+1

    bith[0]+=1
    for a in range(h-1):
        if bith[a]==2:
            bith[a]=0
            bith[a+1]+=1

    if bith[h-1]==2:
        bith[h-1]=0
        bitw[0]+=1

    for b in range(w-1):
        if bitw[b]==2:
            bitw[b]=0
            bitw[b+1]+=1
    if bitw[w-1]>=2:
        break

print(p)

Submission status: Accepted

Solution code:
from itertools import chain, combinations
import copy

def powerset(iterable):
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
def del_list_indexes(l, id_to_del):
    somelist = [i for j, i in enumerate(l) if j not in id_to_del]
    return somelist
def splitw(word): 
    return [char for char in word] 
def countBlacks(rows,paintRows,paintCols):
  c = copy.deepcopy(rows)
  t = 0
  
  c = del_list_indexes(c,paintRows)
  for i in paintCols:
    for ii in c:
      ii[i] = 'r'
  # count
  for i in c:
    for ii in i:
      if ii == "#":
        t +=1

  return t

i = input().split(" ")
h,w,k = int(i[0]),int(i[1]),int(i[2])

rows = []
for i in range(h):
    ii = input()
    rows.append(splitw(ii))
    
    
rowChoices = []
for i in range(h):
  rowChoices.append(str(i)+'row')
colChoices = []
for i in range(w):
  colChoices.append(str(i)+'col')

l = powerset(rowChoices+colChoices)

correct = 0
for i in l:
  paintRows = []
  paintCols = []
  for paint in i:
    if 'row' in paint:
      paintRows.append(int(paint[0]))
    if 'col' in paint:
      paintCols.append(int(paint[0]))
      
  numBlack = countBlacks(rows,paintRows,paintCols)
  if numBlack == k:
    correct += 1
print(correct)

Submission status: Accepted

Solution code:
import copy
H,W,K = map(int,input().split())
c=[] #appendのために宣言が必要
while True:
    try:
        c.append(list(map(str,input())))

    except:
        break;
ans=0
patterns=[]
for i in range(2**(H+W)):
  tmp = [False] * (H+W)
  for j in range(H+W):
    if i >> j & 1:
      tmp[j] = True
  patterns.append(tmp)
  
for pattern in patterns:
  c_tmp=copy.deepcopy(c)
  counter=0
  #print("------------------")
  #print("pattern",pattern)
  for tf in pattern:
    if tf==True:
      if counter<H:#行
        for i in range(W):
          c_tmp[counter][i]="R"
      if counter>=H:#列
        #print(counter)
        for i in range(H):
          c_tmp[i][counter-H]="R"     
    counter+=1
  #print("c_tmp",c_tmp)
      
  num=0
  for row in c_tmp:
    num+=row.count("#")
  #print("num",num)
  #print("ans",ans)
  if num==K:
    ans+=1
    
print(ans)

Submission status: Accepted

Solution code:
n,m,k=map(int,input().split())
ll=[]
tot=0
for i in range(n):
    s=input().split()[0]
    tot+=s.count('#')
    ll.append(s)
x=2**n
y=2**m
#print(x,y)
cou=0

for i in range(x):
    bx=bin(i)[2:]
    bx='0'*(n-len(bx))+bx
    row=[]
    for ii in range(n):
        if(bx[ii]=='0'):
            row.append(ii)
    for j in range(y):
        column=[]
        by=bin(j)[2:]
        by='0'*(m-len(by))+by
        for jj in range(m):
            if(by[jj]=='0'):
                column.append(jj)
        su=0
        #print(row,column,bx,by)
        for ii in row:
            for jj in range(m):
                if(ll[ii][jj]=='#'):
                    su+=1
        #ss=su
        for jj in column:
            for ii in range(n):
                if(ll[ii][jj]=='#'):
                    su+=1
        #print(column,su-ss)
        #print(su)
        for ii in row:
            for jj in column:
                if(ll[ii][jj]=='#'):
                    su-=1
        #print(row,column,su)
        if(tot-su==k):
            #print(row,column,su)
            cou+=1
print(cou)

Submission status: Accepted

Solution code:
H, W, K=map(int, input().split())
s=[]
gyob=[0]*H
retub=[0]*W
for _ in range(H):
  c=input()
  gyob[_]=list(c).count("#")
  for j in range(W):
    if c[j]=="#":
      retub[j]+=1
  s.append(c)
bs=sum(gyob)

gyo=[]
for i in range(1, 2**H):
  l=[]
  for j in range(H):
    if (i>>j)&1:
      l.append(j)
  gyo.append(l)
retu=[]
for i in range(1, 2**W):
  l=[]
  for j in range(W):
    if (i>>j)&1:
      l.append(j)
  retu.append(l)
ans=0
for g in gyo:
  blc=0
  for i in g:
    blc+=gyob[i]
  if bs-blc==K:
    ans+=1
  elif bs-blc<K:
    continue
  for r in retu:
    tmp=0
    for j in r:
      tmp+=retub[j]
      for i in g:
        if s[i][j]=="#":
            tmp-=1
    if bs-(blc+tmp)==K:
      ans+=1
for r in retu:
  blc=0
  for j in r:
    blc+=retub[j]
  if bs-blc==K:
    ans+=1

if bs==K:
  ans+=1
print(ans)

Submission status: Accepted

Solution code:
# import numpy as np


def solve():
    H, W, K = map(int, input().split())
    C = [[] for _ in range(H)]
    for i in range(H):
        tmp = input()
        C[i] = list(tmp)
    # C = np.array(C)
    # print(C)
    ans = 0
    for i in range(2 ** (H + W)):
        cnt = 0
        h_i = []
        w_i = []
        for j in range(H + W):
            if (i >> j) & 1:
                if j < H:
                    h_i.append(j)
                else:
                    w_i.append(j - H)
        for k in range(H):
            for l in range(W):
                if k not in h_i and l not in w_i and C[k][l] == '#':
                    cnt += 1

        if cnt == K:
            ans += 1

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

h_list = []
w_list = []

for n in range(0, h+1):
    for conb in itertools.combinations(range(0, h), n):
        h_list.append(list(conb))
for n in range(0, w+1):
    for conb in itertools.combinations(range(0, w), n):
        w_list.append(list(conb))

ans = 0
for hh in h_list:
    for ww in w_list:
        cnt = 0
        for i in range(h):
            if i in hh:
                continue
            for j in range(w):
                if j in ww:
                    continue
                if s[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 l in range(h)]
gyou=[0]*h
s=0
ans=0
for i in range(h):
    for j in range(w):
        if c[i][j]=="#":
            gyou[i]+=1
            s+=1 
retu=[0]*w
for i in range(w):
    for j in range(h):
        if c[j][i]=="#":
            retu[i]+=1
for i in range(2**(h+w)):
    S=s
    a=[0]*(h+w)
    for j in range(h+w):
        if i>=2**(h+w-j-1):
            i-=2**(h+w-j-1)
            a[j]=1
    for i in range(h):
        if a[i]==1:
            S-=gyou[i]
    for i in range(w):
        if a[h+i]==1:
            S-=retu[i]
    for i in range(h):
        for j in range(w):
            if a[i]==1 and a[h+j]==1 and c[i][j]=="#":
                S+=1
    if S==k:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import itertools

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


def countBlack(c):
    count = 0
    for i in range(H):
        for j in range(W):
            if c[i][j] == "#":
                count += 1
    return count


def makeRededList(c, h_list, w_list):
    new_c = []
    for i in range(H):
        new_c.append([])
        if i in h_list:
            new_c[i] = ["."] * W
        else:
            for j in range(W):
                if (j in w_list):
                    new_c[i].append(".")
                else:
                    new_c[i].append(c[i][j])
    return new_c


c = []


for i in range(H):
    c.append([])
    txt = input()
    for j in txt:
        c[i].append(j)

ans_count = 0

a = []
for i in range(H):
    a.append(f"h{i}")
for i in range(W):
    a.append(f"w{i}")


for i in range(W+H):
    for v in itertools.combinations(a, i):
        h_list = []
        w_list = []
        for string in v:
            if string[0] == "h":
                h_list.append(int(string[1]))
            else:
                w_list.append(int(string[1]))
        if countBlack(makeRededList(c, h_list, w_list)) == K:
            ans_count += 1

print(ans_count)

Submission status: Accepted

Solution code:
import itertools
import copy
def bitsuuretu(n):
    tmp = []
    for i in range(2**n):
        ls = [0] * n
        for j in range(len(ls)):
            if (i >> j) & 1:
                ls[j] += 1
        tmp.append(ls)
    
    return tmp

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

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

CintArray = []
for cs in Carray:
    tmp = []
    for c in cs:
        if(c == "."):
            tmp.append(0)
        else:
            tmp.append(1)
        
    CintArray.append(tmp)

forHbitArray = bitsuuretu(H)
forWbitArray = bitsuuretu(W)

#print(forHbitArray)
#print(forWbitArray)
ans = 0
for Hs in forHbitArray:
    for Ws in forWbitArray:
#        print(Hs, Ws)
#        print(CintArray)
        CarrayChecker = copy.deepcopy(CintArray)
        for Hindex, Hhoge in enumerate(Hs):
            for Windex, Whoge in enumerate(Ws):
#                print(Hhoge, Whoge)

                if(Hhoge == 1 or Whoge == 1):
                    CarrayChecker[Hindex][Windex] = 0
        
#                print(CarrayChecker)
        
#        print(CarrayChecker)
        sumCintArray = 0
        for Cints in CarrayChecker:
            sumCintArray += sum(Cints)

        if(sumCintArray == K):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import copy

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

ans = 0
for i in range(2 ** h):
    for j in range(2 ** w):
        cc = copy.deepcopy(c)
        for k in range(h):
            for l in range(w):
                if ((i >> k) & 1):
                    for m in range(w):
                        cc[k][m] = "1"
                if ((j >> l) & 1):
                    for n in range(h):
                        cc[n][l] = "1"
        cnt = 0
        for o in range(h):
            for p in range(w):
                if cc[o][p] == "#":
                    cnt += 1
        if cnt == x:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"
import copy
#input = sys.stdin.readline

########################################




r , c , k = map(int , input().split())
arr = [list(input()) for i in range(r)]
ans = 0
row = [i for i in range(r)]
col = [i for i in range(c)]
ans = 0
for ii in range(r+1):
	for i in combinations(row,ii):
		for jj in range(c+1):
			for j in combinations(col,jj):
				t = 0
				for r1 in range(r):
					for c1 in range(c):
						if r1 in i or c1 in j:continue
						if arr[r1][c1] == "#":t+=1
				if t == k: ans+=1
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(2 ** h):
    a = deepcopy(c)
    for b in range(h):
        if i >> b & 1:
            a[b] = 'r' * w
    for j in range(2 ** w):
        e = deepcopy(a)
        for l in range(w):
            if j >> l & 1:
                for m in range(h):
                    aa = e[m]
                    e[m] = aa[:l] + 'r' + aa[l + 1:]
        cnt = 0
        aaa = ''.join(e)            
        for d in range(h * w):
            if aaa[d] == '#':
                cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np


def zero_padding(x, num):
    return "0" * (num - len(x)) + x


def main():
    h, w, k = map(int, input().split())
    c = [None] * h
    for i in range(h):
        c[i] = list(map(lambda x: 1 if x == "#" else 0, list(input())))
    c_origin = np.array(c)
    ret = 0
    for i in range(2 ** h):
        for j in range(2 ** w):
            tmp = c_origin.copy()
            a = [_i for _i, x in enumerate(list(zero_padding(f"{i:b}", h))) if x == "1"]
            if a != []:
                tmp[a] = 0
            b = [_j for _j, x in enumerate(list(zero_padding(f"{j:b}", w))) if x == "1"]
            if b != []:
                tmp[:, b] = 0
            if np.sum(tmp) == k:
                ret += 1
    print(ret)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools

h,w,k = map(int,input().split())
c = []
for i in range(h):
    wks = input()
    kk = [ 0 if e == '.' else 1 for e in wks ]
    c.append(kk)

ans = 0

for elc in itertools.product([0,1],repeat=h):
    for elr  in itertools.product([0,1],repeat=w):
        kk = 0
        for i in range(h):
            for j in range(w):
                kk += c[i][j] * elc[i] * elr[j]
        if kk == k :
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import copy
H,W,K=map(int,input().split())
CC=[0]*H
for i in range(H):
    CC[i]=list(input())

count=0
shar=0
kurokuro=0
for i in range(H):
    kurokuro=CC[i].count('#')+kurokuro


#print(kurokuro)
ans=0
for i in range(2**(H+W)):
    kuro=kurokuro
    c=copy.deepcopy(CC)

    for j in range(H+W):
        if((i>>j) & 1):
            if(j<H):
                for q in range(W):
                    if(c[j][q]=='#'):
                        shar=shar+1
                        c[j][q]='.'
                kuro=kuro-shar

                shar=0
            else:
                for q in range(H):
                    if(c[q][j-H]=='#'):
                        shar=shar+1
                        c[q][j-H]='.'

                kuro=kuro-shar
                shar=0

    if(kuro==K):
        ans=ans+1
print(ans)