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 numpy as np

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

board = np.zeros((H, W), dtype=np.uint8)

for h in range(H):
    S = input()
    for w in range(W):
        if S[w] == '#':
            board[h][w] = 1

hlist = board.sum(axis=1)
wlist = board.sum(axis=0)

hbitlist = np.asarray( [ (2**h)*(2**W) for h in range(H) ] )
wbitlist = np.asarray( [  2**w  for w in range(W) ] )

ret = 0
i = 0
loopnum = (2**H)*(2**W)
while True:
    htarget = i & hbitlist
    wtarget = i & wbitlist
    sumnum = 0
    for h in range(H):
            for w in range(W):
                if (htarget[h]==0) and (wtarget[w]==0):
                    sumnum += board[h][w]
    if sumnum == K:
        ret += 1
    i+=1
    if i>=loopnum:
        break

print(ret)

Submission status: Accepted

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

l = []

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


ans = 0
c = 0
for i in range(2**h):
    for j in range(2**w):
        c = 0
        for ii in range(h):
            
            for jj in range(w):
                # print(ii, jj)
                if ( ((i >> ii) & 1) and ( (j >> jj) & 1) )  and l[ii][jj] == '#'   :
        
                    c += 1
        if c == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
gen_input = list(map(int, input().split()))
H = gen_input[0]
W = gen_input[1]
K = gen_input[2]
string = [list(input()) for n in range(H)]

for i in range(len(string)):
    for j in range(len(string[0])):
        if string[i][j] == '.':
            string[i][j] = 100
        else:
            string[i][j] = 1000
            
string = np.array(string)

count = 0

if (string == 1000).sum() == K:
    count += 1
for i in range(2**H):
    for j in range(2**W):
        temp = string.copy()
        I = list(bin(i)[2:].zfill(H))
        J = list(bin(j)[2:].zfill(W))
        fill_h = np.where(np.array(list(map(int, list(I)))) == 1)[0]
        fill_w = np.where(np.array(list(map(int, list(J)))) == 1)[0]

        if len(fill_h) > 0 and len(fill_w) == 0:
            for f in fill_h:
                temp[f, :] = 0
            if (temp == 1000).sum() == K:
                count += 1
        elif len(fill_h) == 0 and len(fill_w) > 0:
            for f in fill_w:
                temp[:, f] = 0
            if (temp == 1000).sum() == K:
                count += 1
        elif len(fill_h) > 0 and len(fill_w) > 0:
            for f in fill_h:
                temp[f, :] = 0
            for f in fill_w:
                temp[:, f] = 0
            if (temp == 1000).sum() == K:
                count += 1

print(count)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
import copy

N,W,K = map(int,input().split())
g_all = np.array([list(input()) for i in range(N)])

K_all = np.count_nonzero(g_all == '#')
count = 0

def dfs(i,g):
  if (i<N):
    g[i,:] = ['r']*W
  else:
    g[:,i-N] = ['r']*N
  return g

g = g_all

for l in range(N+W+1):
  combi = itertools.combinations([i for i in range(N+W)],l)
  for com in combi:
    g = g_all.copy()
    for i in com:
      if (i<N):
        g[i,:] = ['r']*W
      else:
        g[:,i-N] = ['r']*N
    if np.count_nonzero(g == '#') ==K:
      count+=1
print(count)

Submission status: Accepted

Solution code:
import itertools

H, W, K = map(int, input().split())
squares = []
blacks = 0

H_cnt = [0] * H
W_cnt = [0] * W

for i in range(H):
    squares.append(list(input()))
    H_cnt[i] = squares[i].count('#')
    blacks += H_cnt[i]

for i in range(W):
    num = 0
    for j in range(H):
        if squares[j][i] == '#':
            num += 1
    
    W_cnt[i] = num
    
H_p = [0] * (2**H)
for i in range(2**H):
    cnt = 0
    for j in range(H):
        if (i >> j) & 1:
            cnt += H_cnt[j]
    
    H_p[i] = cnt

W_p = [0] * (2**W)
for i in range(2**W):
    cnt = 0
    for j in range(W):
        if (i >> j) & 1:
            cnt += W_cnt[j]
    
    W_p[i] = cnt

ans = 0
for i in range(2**H):
    for j in range(2**W):
        cnt = H_p[i] + W_p[j]
        #print(cnt)
        for k in range(H):
            if (i >> k) & 1:
                for l in range(W):
                    if (j >> l) & 1:
                        if squares[k][l] == '#':
                            #print(bin(i), bin(j), k, l)
                            cnt -= 1
        
        cnt = blacks - cnt
        if cnt == K:
            ans += 1
            
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 21:10:49 2020

@author: Aruto Hosaka
"""


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

# H,W,K = 6,6,8
# C = ['..##..', '.#..#.', '#....#', '######', '#....#', '#....#']

# H,W,K = 6,6,8
# C = [['..##..'], ['.#..#.'], ['#....#'], ['######'], ['#....#'], ['#....#']]

Cn = [[0 for w in range(W)] for h in range (H)]

for h in range(H):
    for w in range(W):
        if C[h][w] == '.':
            Cn[h][w] = 0
        else:
            Cn[h][w] = 1

counter1 = 0

ii = 0

for i in range(2**H):
# for i in range(2):
    for j in range(2**W):
    # for j in range(2):
        i = ii
        for h in reversed(range(H)):
            if i >= 2**h:
                for w2 in range(W):
                    Cn[h][w2] = 0
                i += -2**h
        for w in reversed(range(W)):
            if j >= 2**w:
                for h2 in range(H):
                    Cn[h2][w] = 0
                j += -2**w
        counter = 0
        for h in range(H):    
            counter += sum(Cn[h])
        
        if counter == K:
            counter1 += 1
        
        for h in range(H):
            for w in range(W):
                if C[h][w] == '.':
                    Cn[h][w] = 0
                else:
                    Cn[h][w] = 1
    ii += 1
print(counter1)

Submission status: Accepted

Solution code:
h,w,K=map(int,input().split())
import collections
import itertools
import copy
c = [list(map(str,input().split())) for _ in range(h)]
cc = [[]for i in range(h)]
for i,j in enumerate(c):
    cc[i]=list(c[i][0])

    # print(list(j))

# for i in range(h):
#     for j in range(h):
h_ = 2**h-1
# h_ = bin(h_)
w_ = 2**w-1
# w_ = bin(w_)
count = 0
for i in range(h_):
    for j in range(w_):
        c_ =copy.deepcopy(cc)
        x  = bin(i)[2:].zfill(h)
        y = bin(j)[2:].zfill(w)
        for k in range(h):
            for l in range(w):
                # print(x)
                if x[k]=="1":
                    c_[k]=["."]*w
                    # print("a")

                if y[l]=="1":
                    if y=="000000":
                        print("koko")
                    for m in range(h):
                        # print(m,l)
                        c_[m][l]="."
                # print(c_)
        f = list(itertools.chain.from_iterable(c_))
        z = collections.Counter(f)
        # if x=="100100" and y== "000000":
        #     print(c_)
        # print(z,x,y)
        if h*w-z["."]==K:
                    
            count +=1
print(count)

Submission status: Accepted

Solution code:
import itertools

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

ans = 0
cnt = 0

for a in A:
    for i in range(W):
        if a[i] == "#":
            cnt += 1


def countData(lhs, rhs):
    cnt = 0
    for i in range(H):
        if i in lhs:
            continue
        for j in range(W):
            if j in rhs:
                continue
            if A[i][j] == '#':
                cnt += 1
    return cnt


def countRow(lhs, rhs):
    cnt = 0
    for i in range(H):
        if i == lhs:
            continue
        if i == rhs:
            continue
        for j in range(W):
            if A[i][j] == '#':
                cnt += 1
    return cnt


def countCol(lhs, rhs):
    cnt = 0
    for i in range(H):
        for j in range(W):
            if j == lhs:
                continue
            if j == rhs:
                continue
            if A[i][j] == '#':
                cnt += 1
    return cnt


if cnt < K:
    print(0)
    exit()

stRowlist = [i for i in range(H)]
stCollist = [i for i in range(W)]

# 行列
for i in range(H):
    for rows in itertools.combinations(stRowlist, i):
        for j in range(W):
            for cols in itertools.combinations(stCollist, j):
                cnt = countData(rows, cols)
                if (cnt == K):
                    ans += 1


print(ans)

Submission status: Accepted

Solution code:
h,w,K=map(int,input().split())
c=[]
black=0
hb=[0]*(h)
wb=[0]*(w)
for i in range(h):
    c.append(input())
    for j in range(w):
        if c[i][j]=="#":
            black+=1
            hb[i]+=1

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

ans=0
for i in range(2**h):
    for j in range(2**w):
        ansb=black
        for k in range(h):
            if ((i>>k)&1):
                ansb-=hb[k]
        for l in range(w):
            if((j>>l)&1):
                ansb-=wb[l]
        for k in range(h):
            for l in range(w):
                if((i>>k)&1 and (j>>l)&1 and c[k][l]=="#"):
                    ansb+=1
        if ansb==K:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

mat = []

for i in range(h):
    s = list(input())
    mat.append(s)

brack = 0

for i in range(h):
    for j in range(w):
        if mat[i][j] == "#":
            brack += 1

tate = [0] * w
yoko = [0] * h
for i in range(h):
    for j in range(w):
        if mat[i][j] == "#":
            tate[j] += 1
            yoko[i] += 1

tcom = []
ycom = []
for i in range(w):
    l = list(itertools.combinations(range(w), i+1))
    for j in l:
        tcom.append(j)
for i in range(h):
    l = list(itertools.combinations(range(h), i+1))
    for j in l:
        ycom.append(j)

ans = 0

for i in tcom:
    for j in ycom:
        cnt = 0
        for n in i:
            cnt += tate[n]
        for n in j:
            cnt += yoko[n]
        for n in i:
            for m in j:
                if mat[m][n] == "#":
                    cnt -= 1
        if brack - cnt == k:
            ans += 1

for i in tcom:
    tcnt = 0
    for n in i:
        tcnt += tate[n]
    if brack - tcnt == k:
        ans += 1

for i in ycom:
    ycnt = 0
    for n in i:
        ycnt += yoko[n]
    if brack - ycnt == k:
        ans += 1

if k == brack:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

import copy

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

masume=[]
for i in range(h):
  g=list(input())
  gnumber=[]
  for j in g:
    if j=="#":
      gnumber.append(1)
    else:
      gnumber.append(0)
  masume.append(gnumber)
#print(masume)

#print(np.array(masume))

masume=np.array(masume)

#print([2].append(4))

def aaa(num):
  if num==1:
    return [[0],[1]]
  else:
    tmp=aaa(num-1)
    #print(tmp)
    ret=[]
    for i in tmp:
      #print(i)
      tmp=copy.copy(i)
      i.append(0)
      tmp.append(1)
      ret.append(i)
      ret.append(tmp)
    #print(ret)
    return ret
  


#fff=np.matrix([0,0,0,1,1,1]).T*np.matrix([1,1,0,1,0,1])
#print(fff)
#print(masume)
#fff=np.array(fff)
#print(masume*fff)


tate=aaa(h)
yoko=aaa(w)

ans=0
for i in tate:
  for j in yoko:
    fff=np.matrix(i).T*np.matrix(j)
    #print(fff)
    #print(masume)
    fff=np.array(fff)
    koho=sum(sum(masume*fff))
    if koho==k:
      ans+=1

print(ans)

#for i in tate:
#  for j in yoko:
    #print(np.matrix(i).T*np.matrix(j))

Submission status: Accepted

Solution code:
import copy
h,w,k = map(int, input().split())
lc = []
for _ in range(h):
  cw = str(input())
  tmp = []
  for i in cw:
    if i == "#":
      tmp.append(0)
    else:
      tmp.append(1)
  lc.append(tmp)

#print(lc)
ans = 0

for i1 in range(2**h):
  for j1 in range(2**w):
    lc_tmp = copy.deepcopy(lc) 
    
    for i2 in range(h):
      if (i1 >> i2) &1 == 1:
        for j in range(w):
          lc_tmp[i2][j] += 1

    for j2 in range(w):
      if (j1 >> j2) &1 == 1:
        for i in range(h):
          lc_tmp[i][j2] += 1
            #print(lc_tmp)
    cnt = 0
    for i in range(h):
      cnt += lc_tmp[i].count(0)
    ans += 1 if cnt == k else 0
print(ans)

Submission status: Accepted

Solution code:
H,W,K = map(int,input().split())
L = []
for i in range(H):
    L.append(list(input()))
def cnt(L):
    n = 0
    for i in range(H):
        n += L[i].count('#')
    return n
A = [0,1]
import itertools
B = list(itertools.product(A, repeat=H))
C = list(itertools.product(A, repeat=W))
ans = 0
import copy
for i in range(len(B)):
    D = copy.deepcopy(L)
    for b in range(len(B[i])):
        if B[i][b] == 1:
            for l in range(W):
                D[b][l] = '.'
    for j in range(len(C)):
        E = copy.deepcopy(D)
        for c in range(len(C[j])):
            if C[j][c] == 1:
                for k in range(H):
                    E[k][c] = '.'
        if cnt(E) == K:
            ans += 1
print(ans)

Submission status: Accepted

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

C = [[0 if c == '.' else 1 for c in input()] for i in range(H)]
ans = 0

for i in range(2 ** H):
    T = [A[::] for A in C]
    t = 1
    for k in range(H):
        if t & i > 0:
            for x in range(W):
                T[k][x] = 2
        t <<= 1

    for j in range(2 ** W):
        Q = [A[::] for A  in T]
        s = 1
        for u in range(W):
            if s & j > 0:
                for y in range(H):
                    Q[y][u] = 2
            s <<= 1

        if sum([A.count(1) for A in Q]) == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools as it
H,W,K =map(int,input().split())
C =[]
sharph =[]
sharpw=[]
for i in range(H):
    ci =list(input())
    C.append(ci)
    sharph.append(ci.count("#"))
    
for i in range(W):
    sharpw.append(0)
    for j in range(H):
        if C[j][i] == "#":
            sharpw[i] += 1
sumC =sum(sharpw)

count =0
for h,w in it.product(range(2**H ), range(2**W)):
    a,b,double =0,0,0
    for i in range(H):
        a += int(format(h ,"06b")[- i-1])*sharph[i]
    for j in range(W):
        b += int(format(w ,"06b")[-j -1])*sharpw[j]
    for c,d in it.product(range(1,H+1),range(1,W+1)):
        if int(format(h ,"06b")[- c])== 1and int(format(w ,"06b")[- d]) ==1:
            if C[c-1][d-1] =="#":
                double += 1
    if sumC - a -b + double ==K:
        
        count +=1
    
        

            
print(count)

Submission status: Accepted

Solution code:
import itertools
import copy

h,w,k = map(int,input().split())
c = [list(input()) for i in range(h)]
ans = 0
hh = []
for i in range(h+1):
    hh.append(list(itertools.combinations(range(h+1), i)))
ww = []
for i in range(w+1):
    ww.append(list(itertools.combinations(range(w+1), i)))
# print(hh)
# print(hh[0])

for _ in range(h+1):
    for hs in hh[_]:
        #init
        temp = copy.deepcopy(c)
        # print(c)

        for i in hs:
            # print(i) #i列の塗り潰し
            if i == 0:
                continue
            temp[i-1] = list('r' * w)

        for _ in range(w+1):
            for ws in ww[_]:
                #init
                temp2 = copy.deepcopy(temp)

                for j in ws:
                    # print(i) #j列の塗り潰し
                    if j == 0:
                        continue
                    for ii in range(h):
                        # print(temp[ii][j-1])
                        temp2[ii][j-1] = 'r'
                # print(temp2)
                # 判定
                cnttemp = 0
                for iii in range(h):
                    cnttemp+= temp2[iii].count('#')
                if cnttemp == k:
                    ans += 1

print(ans//4)

Submission status: Accepted

Solution code:
import numpy as np

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

cnt = 0
for i in range(2**H):
    si = list(str(bin(i))[2:].zfill(6))
    for j in range(2**W):
        sj = list(str(bin(j))[2:].zfill(6))
        a = np.array(c[:])
        for k in range(len(a)):
            if si[5-k] == '1':
                a[k] = '.'
        for k in range(len(a[0])):
            if sj[5-k] == '1':
                a[:, k] = '.'
        if np.count_nonzero(a == '#') == K: cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import itertools
h,w,k = map(int, input().split())
g = []
for _ in range(h):
  i = input()
  g.append(i)
l = [0 for j in range(h)]
d = [0 for j in range(w)]
c =0
for i in range(h):
  a = 0
  for j in range(w):
    if g[i][j] == '#':
      a +=1
  l[i]+=a
  c+=a
for i in range(w):
  b = 0
  for j in range(h):
    if g[j][i] == '#':
      b +=1
  d[i]+=b
ans = 0
for i in list(itertools.product([0,1], repeat=h)):
  e = c
  for x in range(h):
    if i[x] == 1:
      e-= l[x]
  for j in list(itertools.product([0,1], repeat=w)):
    f = e
    for y in range(w):
      if j[y] == 1:
        f -= d[y]
    for x in range(h):
      for y in range(w):
        if i[x] == 1 and j[y] == 1 and g[x][y]=='#':
          f+=1
    if f==k:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

f = [[0]*w for i in range(h)]

for i in range(h):
    for j in range(w):
        if c[i][0][j] == '#':
            f[i][j] = 1
cnt = 0
for i in range(1<<h):
    hlist = []
    for ii in range(h):
        if i & (1<<ii):
            hlist.append(ii)
    for j in range(1<<w):
        wlist = []
        for jj in range(w):
            if j & (1<<jj):
                wlist.append(jj)
        #print(hlist)
        #print(wlist)
        ff = np.delete(f, hlist, 0)
        ff = np.delete(ff, wlist, 1)
        # print(ff)
        if ff.sum() == k:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import copy

h, w, x = map(int, input().split())
s = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    c = input()
    s[i] = list(map(int, c.replace('.','0 ').replace('#', '1 ').split()))

t = 0
for i in range(2**h):
    a = copy.deepcopy(s)
    for j in range(h):
        if ((i >> j) & 1):
            for k in range(w):
                a[j][k] = 0
    for j in range(2**w):
        b = copy.deepcopy(a)
        for k in range(w):
            if ((j >> k) & 1):
                for l in range(h):
                    b[l][k] = 0
        result = sum(map(sum, b))
        if x == result:
            t += 1

print(t)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    h, w, k = map(int, input().split())
    c = [list(input()) for i in range(h)]
    ans = 0
    sum_b = 0
    h_b = []
    w_b = [0] * w
    for i in range(len(c)):
        sum_b += c[i].count('#')
        h_b.append(c[i].count('#'))
    for i in range(w):
        for j in range(h):
            if c[j][i] == '#':
                w_b[i] += 1

    for bit_h in range((1 << h)):
        for bit_w in range((1 << w)):
            cnt = 0
            kk = []
            kkk = []
            for i in range(h):
                if bit_h & (1 << i):
                    cnt += h_b[i]
                    kk.append(i)
            for j in range(w):
                if bit_w & (1 << j):
                    cnt += w_b[j]
                    kkk.append(j)
            for i in kk:
                for j in kkk:
                    if c[i][j] == '#':
                        cnt -= 1
            if sum_b - cnt == k:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
  H, W, K = map(int, input().split())
  CC = [[0 for _ in range(W)]  for _ in range(H)]
  for i in range(H):
    for j,s in enumerate(input()):
      if s =='#':
        CC[i][j] = 1
  jkn = 0
  for i in range(2**H):
    for j in range(2**W):
      cnt = 0
      hh = format(i,'b')
      ww = format(j,'b')
      for k in range(len(hh)):
        if hh[len(hh)-k-1]=='1':
          for l in range(len(ww)):
            if ww[len(ww)-l-1]=='1':
              if CC[k][l]==1:
                cnt+=1
      if cnt==K:
        jkn += 1
  print(jkn)
solve()

Submission status: Accepted

Solution code:
H,W,K=map(int,input().split())
c=[]
for i in range(H):
    s=input()
    c.append(s)
blackh=[]
ans=0
for i in range(H):
    h=0
    for j in range(W):
        if c[i][j]=="#":
            h+=1
    blackh.append(h)
blackw=[]
for i in range(W):
    w=0
    for j in range(H):
        if c[j][i]=="#":
            w+=1
    blackw.append(w)
al=sum(blackw)
for i in range(2**H):
    for j in range(2**W):
        b=0
        h=[]
        w=[]
        for k in range(H):
            if ((i>>k)&1):
                b+=blackh[k]
                h.append(k)
        for l in range(W):
            if ((j>>l)&1):
                b+=blackw[l]
                w.append(l)
        for m in w:
            for n in h:
                if c[n][m]=="#":
                    b-=1
        if b==al-K:
            ans+=1
print(ans)

Submission status: Accepted

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

arr = []
for i in range(h):
    string = input()
    line = []
    for moji in string:
        if moji == '.':
            line.append(0)
        else:
            line.append(1)
    arr.append(line)

row = list(range(h))
col = list(range(w))
ans = 0


for bits in product((0, 1), repeat=len(row)):
    combrow = [x for x, bit in zip(row, bits) if bit == 1]
    
    for bits in product((0, 1), repeat=len(col)):
        combcol = [x for x, bit in zip(col, bits) if bit == 1]
    
        tmparr = copy.deepcopy(arr)
        

        for delrow in combrow:
            tmparr[delrow] = [0]*w
        
        for delcol in combcol:
            for i in range(h):
                tmparr[i][delcol]=0
        
        
        count = 0
        for line in tmparr:
            count += sum(line)
        if count == k:
            ans += 1


print(ans)

Submission status: Accepted

Solution code:


import itertools
h,w,k = map(int, input().split())
a = [0]*h
ai= [0]*w*h
bn = 0

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

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            bn +=1

nums = [0,1]
hn = itertools.product(nums, repeat=w+h)

ans = 0

for hi in hn:

    rn =0
    for i in range(h):
        for j in range(w):

            if hi[i]+hi[h+j] >= 1 and a[i][j] == "#":
                rn +=1

   
    if rn == bn-k:
        ans +=1


print(ans)

Submission status: Accepted

Solution code:
import copy
import itertools
h,w,k2 = list(map(int,input().split()))
c = []
res = 0
temp = 0
hc = []
wc = []
a2 = []

hl = [i for i in range(h)]
wl = [i for i in range(w)]

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

for i2 in range(h+1):
    for i in list(itertools.combinations(hl, i2)):
        a = copy.deepcopy(c)
        for j in i:
            for k in range(w):
                a[j][k] = "."
        for i3 in range(w+1):
            for l in list(itertools.combinations(wl, i3)):
                a2 = copy.deepcopy(a)
                for m in l:
                    for n in range(h):
                        a2[n][m] = "."
                temp = 0
                for o in a2:
                    temp += o.count("#")
                if temp == k2:
                    res += 1

print(res)

Submission status: Accepted

Solution code:
# 初期入力

import sys
input = sys.stdin.readline
H,W,K = (int(i) for i in input().split())
c =[["a"]*W for i in range(H)]
for i in range(H):
    #c[i] =input().strip()
    c[i] =list(input().strip())

#どの行または列を選ぶか全探索
from itertools import combinations
from copy import deepcopy

ans =0
for h in range(H+1):
    for w in range(W+1):
        #paint =deepcopy(c)
        for h2 in combinations(list(range(H)), h):
            for w2 in combinations(list(range(W)), w):
                paint =deepcopy(c)
                for h3 in h2:
                    for i in range(W):
                        paint[h3][i] ="r"
                for i in range(H):
                    for w3 in w2:
                        paint[i][w3] ="r"
                #「＃」がいくつあるか
                count_black =0
                for i in range(H):
                    count_black +=paint[i].count("#")
                    #print(count_black,paint[i])
                if count_black ==K:
                    ans +=1

#('a', 'b')('a', 'c')('b', 'c')
print(ans)

Submission status: Accepted

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

tbl = [[0 for i in range(W)] for j in range(H)]
for h in range(H):
    row = input()
    # print(row)
    for i, w in enumerate(row):
        # print(w)
        if w == '.':
            tbl[h][i] = 0
        else:
            tbl[h][i] = 1

# 縦の組み合わせ
hc_list = []
for i in range(H):
    ht = list(itertools.combinations(range(H), i))
    for hc in ht:
        hc_list.append(hc)
# print(hc_list)
# 横の組み合わせ
wc_list = []
for i in range(W):
    wt = list(itertools.combinations(range(W), i))
    for wc in wt:
        wc_list.append(wc)
# print(wc_list)
# 縦横の組み合わせで数字を求める

def count_tbl(tbl):
    cnt = 0
    for t in tbl:
        cnt += sum(t)
    return cnt

# print(count_tbl(tbl))
res = 0
for ht in hc_list:
    thc = copy.deepcopy(tbl)
    for i in ht:
        for j in range(W):
            thc[i][j] = 0
    # print('thc', thc)
    for wt in wc_list:
        # print(wt)
        hwc = copy.deepcopy(thc)
        for k in wt:
            for l in range(H):
                hwc[l][k] = 0
        # print(hwc)
        if count_tbl(hwc) == K:
            # print(hwc)
            res += 1
print(res)

Submission status: Accepted

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    H, W, K = iim()
    S  = [sys.stdin.readline().rstrip() for i in  range(H)]
    B = [1<<i for i in range(max(H,W))]

    k = "#"

    ans = 0
    for i in range(1<< H):
        for j in range(1 << W):
            x = 0
            for h in range(H):
                if i & B[h]: continue
                for w in range(W):
                    if j & B[w]: continue
                    if S[h][w] == k:
                        x += 1

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





if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import itertools

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

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

list_H = [i for i in range(1,H+1)]
list_W = [i for i in range(1,W+1)]

taple_list_H = list()
taple_list_W = list()

for n in range(H+1):
    for x in itertools.combinations(list_H, n):
        taple_list_H.append(x)

for n in range(W+1):
    for x in itertools.combinations(list_W, n):
        taple_list_W.append(x)


res = 0
count = 0

for num_H in taple_list_H:
    copied = data.copy()
    for num in num_H:
        copied[num-1] = '.' * W


    for num_W in taple_list_W:
        copied2 = copied.copy()

        for num in num_W:
            for i in range(H):
                tmp = copied2[i][:num-1] + '.' + copied2[i][num:]
                copied2[i] = tmp
    
        for i in range(H):
            for j in range(W):
                if copied2[i][j] == '#':
                    count += 1
            
        if count == K:
            res += 1
    
        count = 0

print(res)

Submission status: Accepted

Solution code:
import numpy as np
import copy

if __name__ == '__main__':
    H, W, K = map(int, input().split(' '))
    C = np.zeros([H, W], dtype=bool)
    for i in range(H):
        tmp = input()
        for j in range(W):
            if tmp[j] == ".":
                C[i][j] = False
            if tmp[j] == "#":
                C[i][j] = True

    count = 0
    for i in range(2**H):
        tmp1 = copy.copy(C)
        for j in range(H):
            if ((i>>j) & 1):
                tmp1[j,:] = False

        for ii in range(2**W):
            tmp2 = copy.copy(tmp1)
            for jj in range(W):
                if ((ii>>jj) & 1):
                    tmp2[:, jj] = False

            if np.count_nonzero(tmp2) == K:
                count += 1

    print(count)