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
h, w, k = map(int, input().split())
ans = 0
s = [input() for _ in range(h)]
for hi in itertools.product([0, 1], repeat=h):
	for wi in itertools.product([0, 1], repeat=w):
		cnt = 0
		for i, j in itertools.product(range(h), range(w)):
			if hi[i] and wi[j]:
				if s[i][j] == "#":
					cnt += 1
		if cnt == k:
			ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
import copy
def count_hash(arr):
    b_count = 0
    for v in arr:
        for r in v:
            if r == "#":
                b_count += 1
    return b_count
def h_and_v(arr, k):
    rows = len(arr)
    cols = len(arr[0])
    mix_arr = []
    for i in range(rows):
        mix_arr.append(str(i) + "r")
    for j in range(cols):
        mix_arr.append(str(j) + "c")
    combo_arr = []
    for i in range(0, len(mix_arr)):
        temp_arr = list(itertools.combinations(mix_arr, i))
        combo_arr.append(temp_arr)
    del temp_arr
    del mix_arr
    all_combo = []
    for v in combo_arr:
        for r in v:
            all_combo.append(r)
    count = 0
    for a in all_combo:
        temp = copy.deepcopy(arr)
        for i, r in enumerate(a):
            if r[-1] == "r":
                temp[int(r[0])][:] = ["r"]*(len(temp[0]))
            else:
                for i in range(len(temp)):
                    temp[i][int(r[0])] = "r"
        if count_hash(temp) == k:
            count += 1
    print(count, end="")




def start():
    h,w,k = [int(v) for v in input().split(" ")]
    arr = []
    for i in range(h):
        arr.append([char for char in input()])
    h_and_v(arr, k)

start()

Submission status: Accepted

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


print(ans)

Submission status: Accepted

Solution code:
inp = list(map(int,input().split()))
row=inp[0]
col=inp[1]
k=inp[2]
arr=[]
for i in range(row):
    s=input()
    arr.append(s)
ans=0
for i in range((1<<row)-1,-1,-1):
    for j in range((1<<col)-1,-1,-1):
        black=0
        for a in range(row):
            for b in range(col):
                if ((i>>a)&1 ==0 and (j>>b)&1 ==0):
                    if arr[a][b]=='#':
                        black+=1
        if black==k:
            ans+=1
print (ans)

Submission status: Accepted

Solution code:
import itertools
h, w, k = map(int, input().split())
ans = 0
s = [input() for _ in range(h)]
for hi in itertools.product([0, 1], repeat=h):
	tmp = s[:]
	for j in range(h):
		if hi[j] == 1:
			tmp[j] = "."*w
	for wi in itertools.product([0, 1], repeat=w):
		cnt = 0
		for i in range(h):
			for j in range(w):
				if wi[j]:
					if tmp[i][j] == "#":
						cnt += 1
		if cnt == k:
			ans += 1
print(ans)

Submission status: Accepted

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

    sharpNum = 0

    for i in range(H):
        rowString = input()

        colSharpNum = rowString.count("#")
        sharpNum = sharpNum + colSharpNum
        wField = []

        for j in range(W):
            wField.append(rowString[j])
                    
        Field.append(wField)
    
    answer = 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 Field[i][j] == "#":
                        black = black + 1
            if black == K:
                answer = answer + 1

    print(answer)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W, K = map(int, readline().split())
    G = [readline() for _ in range(H)]

    ans = 0
    for mask_r in range(1 << H):
        for mask_c in range(1 << W):
            black = 0
            for i in range(H):
                for j in range(W):
                    if ((mask_r & (1 << i)) == 0) and ((mask_c & (1 << j)) == 0) and G[i][j] == '#':
                        black += 1
            if black == K:
                ans += 1

    print(ans)
    return


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 ib in range(1<<h):
    for jb in range(1<<w):
        cc = 0
        for i in range(h):
            if ib&(1<<i):continue
            for j in range(w):
                if jb&(1<<j):continue
                cc += c[i][j]=="#"
        if cc==k: ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
# 全パターン検索 真偽値表
for rows in product([True, False], repeat=H):
    # print(rows)
    for cols in product([True, False], repeat=W):
        # print(cols)
        black = 0
        for r, c in product(range(H), range(W)):
            # print("{}:{}".format(r,c))
            if rows[r] and cols[c] and C[r][c] == '#':
                black += 1
        if black == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys


def resolve():
    """
    全パターンは2**12=4096通りだからbit全探索
    消さない行列だけ判定するコードの方がスマート？(解説動画より)
    """

    readline = sys.stdin.readline    # 1行だけ文字列にする

    H, W, K = map(int, readline().split())
    c = [list(readline().strip()) for _ in [0] * H]
    ans = 0

    # bit全探索
    for bit_i in range(1 << H):
        for bit_j in range(1 << W):
            cnt = 0
            for i in range(H):
                for j in range(W):
                    if (1
                            and bit_i & (1 << i)
                            and bit_j & (1 << j)
                            and c[i][j] == '#'):
                        cnt += 1
            if cnt == K:
                ans += 1
    print(ans)


resolve()

Submission status: Accepted

Solution code:
#n = int(input())
from collections import deque

h,w,ans = map(int,input().split())
tmap = ['']*w
map = []
count = 0

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

for i in range(2**h):
    for j in range(2**w):
        map2 = []
        tmap2 = ['']*w
        sharp = 0
        for k in range(h):
            if((i>>k)&1):
                map2.append(['.']*w)
            else:
                map2.append(map[k])
            for l in range(w):
                tmap2[l] += map2[k][l]
        for k in range(w):
            if not((j>>k)&1):
                sharp += tmap2[k].count('#')
        if sharp == ans:
            count += 1
        #print(i,j,sharp,map2,tmap2)

print(count)

Submission status: Accepted

Solution code:
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College

'''
from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')

file=0



def solve():
    
    # for _ in range(ii()):
    h,w,k=mi()
    a=[]
    cnt=0
    for i in range(h):
        a.append(si())
        for j in a[i]:
            if j=='#':
                cnt+=1
    ans=0
    # print(cnt)
    for i in range(1<<(h+w)):
        c=set()
        x=[]
        y=[]
        for j in range(h):
            if (i>>j)&1:
                x.append(j)
                for k1 in range(w):
                    if a[j][k1]=='#':
                        c.add(tuple([j,k1]))
        for j in range(w):
            if (i>>(h+j))&1:
                for k1 in range(h):
                    if a[k1][j]=='#':
                        c.add(tuple([k1,j]))
        c1=cnt-len(c)
        if(c1==k):
            # print(c,i,x,y)
            ans+=1
        
    print(ans)



 









if __name__ =="__main__":

    if(file):

        if path.exists('input1.txt'):
            sys.stdin=open('input1.txt', 'r')
            sys.stdout=open('output1.txt','w')
        else:
            input=sys.stdin.readline
    solve()

Submission status: Accepted

Solution code:
H,W,K = map(int,input().split())
s = [list(input()) for i in range(H)]
ans = 0

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

Submission status: Accepted

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


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    H, W, K = list(map(int, input().split()))
    c = []
    for h in range(H):
        c.append(input())

    return H, W, K, c


def main(H: int, W: int, K: int, c: list) -> None:
    """
    メイン処理.

    Args:\n
        H (int): 行数（1 <= H <= 6）
        W (int): 列数（1 <= W <= 6）
        K (int): 正の整数（1 <= K <= HW）
        c (list): マスの色
    """
    # "." = 0, "#" = 1の配列に変換
    l = np.zeros(shape=(H, W))
    for h, w in itertools.product(range(H), range(W)):
        l[h, w] = (c[h][w] == "#")

    # 求解処理
    ans = 0
    for h_bit, w_bit in itertools.product(range(1 << H), range(1 << W)):
        l_copy = l.copy()
        for h in range(H):
            if h_bit & (1 << h):
                l_copy[h, :] = [0]
        for w in range(W):
            if w_bit & (1 << w):
                l_copy[:, w] = [0]
        ans += (np.sum(l_copy) == K)

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    H, W, K, c = get_input()

    # メイン処理
    main(H, W, K, c)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
c = [0] * H
ans = 0
for i in range(H):
    c[i] = input()
for row in range(1 << H):
    for line in range(1 << W):
        black = 0
        for h in range(H):
            if (row >> h) % 2 == 1:
                continue
            for w in range(W):
                if (line >> w) % 2 == 1:
                    continue
                if c[h][w] == '#':
                    black += 1
        if black == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int,input().split())
colors = []
for i in range(H):
    colors+=input().split()

ans=0
for maskH in range(1 << H):
    for maskW in range(1 << W):
        black = 0
        for i in range(H):
            for j in range(W):
                if ((maskH >> i) & 1)==0 and ((maskW >> j) & 1)==0 and colors[i][j]=="#":
                    black+=1
        if black==K: ans+=1
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
g = [input() for _ in range(H)]
ans = 0
for bit in range(2**(H+W)):
    cnt = 0
    for h in range(H):
        if ((bit >> h) & 1):
            continue
        for w in range(W):
            if ((bit >> H + w) & 1):
                continue
            if g[h][w] == '#':
                cnt += 1
    if cnt == K:
        ans += 1
print(ans)

Submission status: Accepted

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

ttcl = [x for x in zip(*cl)]
tcl = []
for i in range(len(ttcl)):
  tt = "".join(ttcl[i])
  tcl.append(tt)

n = h
hb = ['0'] * n
hbl = []
for bit in range(1 << n):
  for i in range(n):
    if (bit >> i) & 1:
      hb[i] = '1'
    else:
      hb[i] = '0'
  hbl.append("".join(hb))

n = w
wb = ['0'] * n
wbl = []
for bit in range(1 << n):
  for i in range(n):
    if (bit >> i) & 1:
      wb[i] = '1'
    else:
      wb[i] = '0'
  wbl.append("".join(wb))

rc = 0
for i in range(len(hbl)):
  for j in range(len(wbl)):
    tbc = 0
    for m in range(h):
      for n in range(w):
        if (hbl[i][m] == '1') and (wbl[j][n] == '1'):
          if cl[m][n] == '#':
            tbc += 1
    if tbc == k:
      rc += 1
print(rc)

Submission status: Accepted

Solution code:
H,W,K=map(int,input().split())
import numpy as np
import copy
c=[]
for i in range(H):
  c.append(list(input().replace('.','0').replace('#','1')))

def count(xdel,ydel,l):
  cnt=0
  for i in range(H):
      for j in range(W):
        if 2**i&ydel!=0 or 2**j&xdel!=0:
          l[i][j]=2
        if l[i][j]=='1':
          cnt+=1
          l[i][j]=1
        
  return cnt

result=0
for i in range(2**H):
  for j in range(2**W):
    l=copy.deepcopy(c)
    if count(j,i,l)==K:
      result+=1
print(result)

Submission status: Accepted

Solution code:
def count(C, H, W):
    v = 0
    for h in range(H):
        for w in range(W):
            if C[h][w] == '#':
                v += 1
    return v

def main():
    H, W, K, = map(int, input().split())
    C = []
    for _ in range(H):
        C.append([c for c in input()])
    # print(H, W, K, C)
    ans = 0
    for h in range(2**H - 1):
        D = []
        for i in range(H):
            if (h >> i) & 1 == 1:
                D.append(['-' for w in range(W)])
            else:
                D.append([C[i][w] for w in range(W)])
        for w in range(2**W):
            E = []
            for a in range(H):
                E.append([D[a][b] for b in range(W)])
            for j in range(W):
                if (w >> j) & 1 == 1:
                    for k in range(H):
                        E[k][j] = '-'
            v = count(E, H, W)
            # print(h, w, v, D)
            if v == K:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

# 標準入力を取得
H, W, K = list(map(int, input().split()))
c = []
for h in range(H):
    c.append(input())

# 求解処理
l = np.zeros(shape=(H, W))
for h, w in itertools.product(range(H), range(W)):
    l[h, w] = (c[h][w] == "#")

ans = 0
for h_bit, w_bit in itertools.product(range(1 << H), range(1 << W)):
    l_copy = l.copy()
    for h in range(H):
        if h_bit & (1 << h):
            l_copy[h, :] = [0]
    for w in range(W):
        if w_bit & (1 << w):
            l_copy[:, w] = [0]
    ans += (np.sum(l_copy) == K)

# 結果出力
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import product

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

a = np.array([list(input()) for _ in range(h)])

cnt = 0
for rows in product([False, True], repeat = h):
    for cols in product([False, True], repeat = w):
        if np.count_nonzero(a[np.ix_(rows,cols)]=='#') == k:
           cnt += 1

print(cnt)

Submission status: Accepted

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

total = 0

for i in range(2**(H)):
  for j in range(2**(W)):
    pattern = 0
    bin_H = '{:09b}'.format(i)[-H:]
    bin_W = '{:09b}'.format(j)[-W:]
    for hi,h in enumerate(bin_H):
      if h == '0':
        for wi,w in enumerate(bin_W):
          if w == '0' and C[hi][wi] == "#":
            pattern += 1
    if pattern == K:
      total += 1
print(total)

Submission status: Accepted

Solution code:
from itertools import *
h,w,k=map(int,input().split())
c=[]
s=[]
H=[i for i in range(h)]
W=[i for i in range(w)]
ans=0
for i in range(h):
    c.append(list(input()))
for i in range(2**h):
    for j in range(2**w):
        tmp=0
        for ii in range(h):
            for jj in range(w):
                if ((i>>ii)&1) and ((j>>jj)&1):
                    if c[ii][jj]=="#":
                        tmp+=1
        if tmp==k:
            ans+=1
                        
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
'''
K = 2
H, W = 5, 5
a = np.array([
	[0, 0, 0, 0, 1],
	[0, 0, 0, 1, 1],
	[0, 0, 1, 1, 1],
	[0, 1, 1, 1, 1],
	[1, 1, 1, 1, 1]
])
'''

def conv(c):
	#print(c)
	return int(c=='#')
H, W, K = map(int, input().split())
a = np.array([list(map(conv, input())) for _ in range(H)])
count = 0
for i in range(2 ** H - 1):
	b = np.delete(a.copy(), [j for j in range(H) if ((i >> j) & 1)], 0)
	blen = b.shape[1]
	for i in range(2 ** W - 1):
		c = np.delete(b, [j for j in range(blen) if ((i >> j) & 1)], 1)
		#print(np.sum(c))
		if K==np.sum(c):
			count += 1
print(count)
print()

Submission status: Accepted

Solution code:
H, W, K =  [int(i) for i in input().split()]

masme = []
for i in range(H):
    masme.append(list(input()))

#print(masme)

h_p = []
for h in range(pow(2,H)):
    h_p.append( [int(i) for i in list(str(bin(h))[2:].zfill(H))] )

#print(h_p)

w_p = []
for w in range(pow(2,W)):
    w_p.append( [int(i) for i in list(str(bin(w))[2:].zfill(W))] )

#print(w_p)

def count(mas, h_b, w_b):
    ans = 0
    for i in range(H):
        for j in range(W):
            if h_b[i] * w_b[j] == 1 and mas[i][j] == "#" :
                ans += 1
    return ans


ans_cnt = 0

for h in h_p:
    for w in w_p:
        cnt = 0
        for i in range(H):
            for j in range(W):
                if h[i] * w[j] == 1 and masme[i][j] == "#" :
                    cnt += 1
        if(cnt == K):
            ans_cnt += 1

print(ans_cnt)

Submission status: Accepted

Solution code:
H, W, K =  [int(i) for i in input().split()]

masme = []
for i in range(H):
    masme.append(list(input()))

#print(masme)

h_p = []
for h in range(pow(2,H)):
    h_p.append( [int(i) for i in list(str(bin(h))[2:].zfill(H))] )

#print(h_p)

w_p = []
for w in range(pow(2,W)):
    w_p.append( [int(i) for i in list(str(bin(w))[2:].zfill(W))] )

ans_cnt = 0

for h in h_p:
    for w in w_p:
        cnt = 0
        for i in range(H):
            for j in range(W):
                if h[i] * w[j] == 1 and masme[i][j] == "#" :
                    cnt += 1
        if(cnt == K):
            ans_cnt += 1

print(ans_cnt)

Submission status: Accepted

Solution code:
def main():
    H,W,K = [int(x) for x in input().split()]

    B = 0
    BH = [0]*H
    BW = [0]*W
    BHW = []
    for h in range(H):
        BHW.append([0]*W)
    for i in range(H):
        C = list(input())
        for j in range(W):
            if C[j] == '#':
                B += 1
                BH[i] += 1
                BW[j] += 1
                BHW[i][j] = 1

    cnt = 0
    for ibit in range(0,1<<H):
        for jbit in range(0,1<<W):
            icost = 0
            jcost = 0
            ijcost = 0
            for i in range(H):
                if (1<<i) & ibit:
                    icost += BH[i]
            for j in range(W):
                if (1<<j) & jbit:
                    jcost += BW[j]
            for i in range(H):
                for j in range(W):
                    if (1<<i) & ibit and (1<<j) & jbit:
                        ijcost += BHW[i][j]
            b = B - icost - jcost + ijcost
            if K == b:
                cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


num_h = 2**h-1
num_w = 2**w-1
result = 0
for i in range(num_h):
  for j in range(num_w):
    tmp = 0
    for row in range(h):
      for col in range(w):
        if (i >> row) & 1 == 1:
          continue
        if (j >> col) & 1 == 1:
          continue
        if c[row][col] == '#':
          tmp += 1
    if tmp == k:
      result += 1

print(int(result))

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
g = [input() for _ in range(h)]
ans = 0
for bit in range(2**(h+w)):
    cnt = 0
    for hh in range(h):
        if ((bit >> hh) & 1):
            continue
        for ww in range(w):
            if ((bit >> h + ww) & 1):
                continue
            if g[hh][ww] == '#':
                cnt += 1
    if cnt == k:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

c = [['r' for j in range(w)] for i in range(h)]

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

for i in range(2**h):
  x = 0
  h_flag = [0]*(h)
  while i != 0:
      if i % 2 == 1:
        h_flag[x] = 1
      i = i // 2
      x += 1
  for j in range(2**w):
    black = 0
    w_flag = [0]*(w)
    y = 0
    while j != 0:
      if j % 2 == 1:
        w_flag[y] = 1
      j = j // 2
      y += 1
    for m in range(h):
      for n in range(w):
        if c[m][n] == '#' and h_flag[m] == 0 and w_flag[n] == 0:
          black += 1
#    print(h_flag,w_flag,black)
    if black == k:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
H, W, K =  [int(i) for i in input().split()]

masme = []
for i in range(H):
    masme.append(list(input()))

#print(masme)

h_p = []
for h in range(pow(2,H)):
    h_p.append( [int(i) for i in list(str(bin(h))[2:].zfill(H))] )

#print(h_p)

w_p = []
for w in range(pow(2,W)):
    w_p.append( [int(i) for i in list(str(bin(w))[2:].zfill(W))] )

#print(w_p)

def count(mas, h_b, w_b):
    ans = 0
    for i in range(H):
        for j in range(W):
            if h_b[i] * w_b[j] == 1 and mas[i][j] == "#" :
                ans += 1
    return ans


ans_cnt = 0
for h in h_p:
    for w in w_p:
        cnt = count(masme, h, w)
        if(cnt == K):
            ans_cnt += 1

print(ans_cnt)

Submission status: Accepted

Solution code:
import itertools
import copy

H, W, K = map(int, input().split())
C = [list(input()) for i in range(H)]
clist = list(itertools.product([0, 1], repeat=H+W))
        
ans = 0
for q in clist:
  black = 0
  h = q[:H]
  w = q[H:]
  for i in range(H):
    for j in range(W):
      if h[i] == w[j] == 0 and C[i][j] == '#':
        black += 1
  if black == K:
    ans += 1
    #print(q)

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

def main():
	h,w,k=MI()
	G=[]
	for _ in range(h):
		G.append(list(input().rstrip().decode()))
	#print(G)
	ans=0

	for i in range(1<<h):
		for j in range(1<<w):
			cnt=0
			for ii in range(h):
				for jj in range(w):
					#print(i,j,ii,jj,)
					if i&1<<ii and j&1<<jj and G[ii-1][jj-1]=="#":
						#print(1<<i)
						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 i in range(h)]
ans = 0
for i in range(1<<h):
    for j in range(1<<w):
        cnt = 0
        for x in range(h):
            if (i>>x)&1 == 1:
                continue
            for y in range(w):
                if (j>>y)&1 == 1:
                    continue
                if C[x][y] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import copy
import collections
import itertools
h,w,k=map(int,input().split())
a=[[i for i in input()] for j in range(h)]
cnt=0
for row in itertools.product([True,False],repeat=h):
    for col in itertools.product([True,False],repeat=w):
        d=copy.deepcopy(a)
        for x in range(w):
            for y in range(h):
                if row[y] or col[x]:d[y][x]="@"
        cc=collections.Counter(list(itertools.chain.from_iterable(d)))
        if cc["#"]==k:cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
def main():
    h,w,k = map(int,input().split())
    Map = []
    for i in range(h):
        tmp = list(input())
        Map.append(tmp)
    ans = 0
    
    for i in range(2**h-1):
        for j in range(2**w-1):
            black = 0
            for y in range(h):
                for x in range(w):
                    if ((i>>y)&1==0) and ((j>>x)&1==0) and Map[y][x]=='#':
                        black += 1
            if black==k:
                ans += 1
    print(ans)
                        
main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W, K = MAP()
c = [list(input()) for _ in range(H)]
S = [[0] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        if c[i][j] == "#":
            S[i][j] = 1
S = np.array(S, dtype=np.int32)

ans = 0
for y in product([0, 1], repeat=H):
    for x in product([0, 1], repeat=W):
        Y = [i for i, n in enumerate(y) if n]
        X = [i for i, n in enumerate(x) if n]
        mask = np.zeros((H, W))
        mask[np.ix_(Y, X)] = 1
        ans += np.sum(mask * S) == K
print(ans)

Submission status: Accepted

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

    ans = 0
    for rows in product([True, False], repeat=H):
        for cols in product([True, False], repeat=W):
            remain = 0
            for r, c in product(range(H), range(W)):
                if rows[r] and cols[c] and C[r][c] == '#':
                    remain += 1
            if remain == K:
                ans += 1
    return ans

print(c_h_and_v())

Submission status: Accepted

Solution code:
import copy
H, W, K = map(int, input().split())
A = [list(input()) for i in range(H)]
ans = 0
for i in range(2**H):
    for j in range(2**W):
        s1 = format(i, "0%ib" % H)
        s2 = format(j, "0%ib" % W)
        C = copy.deepcopy(A)
        for _i in range(H):
            if s1[_i] == "1":
                for x in range(W):
                    C[_i][x] = "r"
        for _j in range(W):
            if s2[_j] == "1":
                for y in range(H):
                    C[y][_j] = "r"
        cnt = 0
        for ii in range(H):
            for jj in range(W):
                cnt += int(C[ii][jj] == "#")
        ans += int(cnt == K)
print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
C = []
for _ in range(h):
    C.append(input())
ans = 0
for hbit in range(1<<h): # red row bit
    for wbit in range(1<<w): # red col bit
        c = 0
        for i in range(h):
            for j in range(w):
                if hbit>>i & 1 and wbit>>j & 1 and C[i][j] == '#': c += 1
        if c == 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))

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


#いじってもいいやつを設定する
import copy
c_copy = copy.deepcopy(c)

#行の操作(h)
g = []
for i in range(2 ** h) :
    gyou = ["0"] * h
    for j in range(h):
        if ((i >> j) & 1):
            gyou[j] = "1"
    g.append(gyou)
#列の操作(w)
r = []
for p in range(2 ** w):
    retsu = ["0"] * w
    for q in range(w):
        if ((p >> q) & 1):
            retsu[q] = "1"
    r.append(retsu)

#行列を"."にする
def aka(a,b):
    #行を.にする
    for i in range(h) :
        if g[a][i] == "1" :
            for k in range(w) :
                c_copy[i][k] = "."
    #列を.にする
    for j in range(w) :
        if r[b][j] == "1" :
            for l in range(h) :
                c_copy[l][j] = "."
    return c_copy

import itertools

ans = 0
for a in range(2**h):
    for b in range(2**w):
        l = list(itertools.chain.from_iterable(aka(a,b)))
        if l.count('#') == k :
            ans += 1
        c_copy = copy.deepcopy(c)

print(ans)

Submission status: Accepted

Solution code:
import itertools
H,W,K=map(int,input().split())
c = [list(input()) for _ in range(H)]
#print(c)
h=list(itertools.product(range(2), repeat = H))
w=list(itertools.product(range(2), repeat = W))
a= [[0 for i in range(len(w))] for j in range(len(h))] ##掛け算で書いてはいけない
ans= [[0 for i in range(len(w))] for j in range(len(h))]
#print(w)
#print(a)

for i in range(len(h)):
    for j in range(len(w)):
        cnt=0
        for ii in range(H):
            for jj in range(W):
                #print(i,j,ii,jj)
                if h[i][ii] == 1 and w[j][jj] == 1:
                    if c[ii][jj] == '#':
                        cnt+=1
        a[i][j] = cnt
        if cnt == K:
            ans[0][0] += 1

sum=0
for i in range(len(h)):
    for j in range(len(w)):
        sum+=ans[i][j]
print(sum)