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: Wrong Answer

Solution code:
from copy import deepcopy
from itertools import chain
def main():
    h,w,k=map(int,input().split())
    C=[]
    Copy=[]
    for i in range(h):
        C.append(list(input()))
    hw=4000
    jh=0
    al=[]
    for i in range(hw):
        Copy=deepcopy(C)
        try:
            for j in range(len(str(bin(i)))):
                if (i>>j)&1:
                    if j>h-1:
                        jh=j-h
                        for K in range(h):
                            Copy[K][jh]="%"
                    else:
                        for K in range(w):
                            Copy[j][K]="%"
        except:
            pass
        al.append("".join(list(chain.from_iterable(Copy))))
    xx=list(set(al))
    c=0
    for i in range(len(xx)):
        zz=xx[i].count("#")
        if zz==k:
            c+=1
    print(c)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
from copy import deepcopy
from itertools import chain
def main():
    h,w,k=map(int,input().split())
    C=[]
    Copy=[]
    for i in range(h):
        C.append(list(input()))
    hw=3800
    jh=0
    al=[]
    for i in range(hw):
        Copy=deepcopy(C)
        try:
            for j in range(len(str(bin(i)))):
                if (i>>j)&1:
                    if j>h-1:
                        jh=j-h
                        for K in range(h):
                            Copy[K][jh]="%"
                    else:
                        for K in range(w):
                            Copy[j][K]="%"
        except:
            pass
        al.append("".join(list(chain.from_iterable(Copy))))
    xx=list(set(al))
    c=0
    for i in range(len(xx)):
        zz=xx[i].count("#")
        if zz==k:
            c+=1
    print(c)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def sumup(lst):
  sum = 0
  for i in range(len(lst)):
    sum += int(lst[i])
  return sum
h, v, k = map(int,input().split())
C = []
for i in range(h):
    l = input()
    C.append(l)
    
black_hcounter = []
black_vcounter = []
for i in range(h):
  counter = 0
  for j in range(v):
    if C[i][j] == "#":
      counter += 1
  black_hcounter.append(counter)
sum = sum(black_hcounter)
for j in range(v):
  counter = 0
  for i in range(h):
    if C[i][j] == "#":
      counter += 1
  black_vcounter.append(counter)
  
ans = 0
herasu = sum - k
if k == sum:
  ans = 1
else:
  for i in range(1<<h):
    l = []
    for j in range(h):
        if (i>>j & 1) == 1:
          l.append(black_hcounter[j])
    if len(l) > 0 and sumup(l) == herasu:
        ans += 1
  for i in range(1<<v):
    l = []
    for j in range(v):
        if (i>>j & 1) == 1:
          l.append(black_vcounter[j])
    if len(l) > 0 and sumup(l) == herasu:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
H,W,K= map(int,input().split())
List=[list(input()) for i in range(H)]
nums=[]
total=0
for i in range(1,H+W+1):
    nums.append(i)
for q in range(0,H+W+1):
    hoge=[]
    for balls in itertools.combinations(nums, q):
        hoge.append(balls)
    for p in range(0,len(hoge)):
        List_sub=List
        for i in range(1,H+1):
            if i in hoge[p]:
                for j in range(0,W):
                    List_sub[i-1][j]="x"
        for i in range(H+1,H+W+1):
            if i in hoge[p]:
                for j in range(0,H):
                    List_sub[j][i-H-1]="x"
        s=0
        for i in range(0,H):
            for j in range(0,W):
                if List_sub[i][j]=="#":
                    s+=1
        if s== K:
            total+=1
print(total)

Submission status: Wrong Answer

Solution code:
from itertools import product
import copy
H,W,K=map(int,input().split())
C=[]
if H==1 and W==1:
    tp=input()
    if tp=='#':
        print(0)
    else:
        print(1)
    exit()

else:
    for _ in range(H):
        C.append(list(input()))
    ans=0
    cnt=0
    for h in product(range(2),repeat=H):
        for w in product(range(2),repeat=W):
            num=0
            C_cp=copy.deepcopy(C)
            #print('C_cp_is',C_cp)
            for j in range(W):
                if w[j]==1:
                    for i in range(H):
                        C_cp[i][j]='r'

            for i in range(H):
                if h[i]==1:
                    C_cp[i]='r'
           # print(h,w)
            #print(C_cp)
            for i in range(H):
                num+=C_cp[i].count('#')
           # print(num)
            if num==K:
                ans+=1
                if (all(h)==True or all(w)==True) and (H==1 or W==1):
                    cnt+=1

print(ans-cnt//2)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
def sumup(lst):
  sum = 0
  for i in range(len(lst)):
    sum += int(lst[i])
  return sum
h, v, k = map(int,input().split())
C = []
for i in range(h):
    l = input()
    C.append(l)
    
black_hcounter = []
black_vcounter = []
for i in range(h):
  counter = 0
  for j in range(v):
    if C[i][j] == "#":
      counter += 1
  black_hcounter.append(counter)
sum = sum(black_hcounter)
for j in range(v):
  counter = 0
  for i in range(h):
    if C[i][j] == "#":
      counter += 1
  black_vcounter.append(counter)
  
ans = 0
herasu = sum - k
if k == sum:
  ans = 1
else:
  for i in range(1<<h):
    l = []
    for j in range(h):
        if (i>>j & 1) == 1:
          l.append(black_hcounter[j])
    if len(l) > 0 and sumup(l) == herasu:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
h,w,k=map(int,input().split())
g=np.ones((h,w))
l=['' for _ in range(h)]
for i in range(h):
  l[i]=str(input())
for i in range(h):
  for j in range(w):
    if l[i][j]=='.': g[i][j]=0
s=np.sum(g)
ans=0
for i in range(h):
  for j in range(w):
    u=list(itertools.combinations(range(h),i))
    v=list(itertools.combinations(range(w),j))
    for x in u:
      for y in v:
        a=0
        b=0
        c=0
        for p in x:
          a+=np.sum(g[p,:])
        print(a)
        for q in y:
          b+=np.sum(g[:,q])
        print(b)
        for p in x:
          for q in y:
            c+=g[p][q]
        print(s-a-b+c)
        if s-a-b+c==k: 
          ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from itertools import chain
def main():
    h,w,k=map(int,input().split())
    C=[]
    Copy=[]
    for i in range(h):
        C.append(list(input()))
    hw=3600
    jh=0
    al=[]
    for i in range(hw):
        Copy=deepcopy(C)
        try:
            for j in range(len(str(bin(i)))):
                if (i>>j)&1:
                    if j>h-1:
                        jh=j-h
                        for K in range(h):
                            Copy[K][jh]="%"
                    else:
                        for K in range(w):
                            Copy[j][K]="%"
        except:
            pass
        al.append("".join(list(chain.from_iterable(Copy))))
    xx=list(set(al))
    c=0
    for i in range(len(xx)):
        zz=xx[i].count("#")
        if zz==k:
            c+=1
    print(c)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from itertools import product
import copy
H,W,K=map(int,input().split())
C=[]
if H==1 and W==1:
    tp=input()
    if tp=='#':
        print(0)
    else:
        print(1)
    exit()

else:
    for _ in range(H):
        C.append(list(input()))
    ans=0
    cnt=0
    for h in product(range(2),repeat=H):
        for w in product(range(2),repeat=W):
            num=0
            C_cp=copy.deepcopy(C)
            print('C_cp_is',C_cp)
            for j in range(W):
                if w[j]==1:
                    for i in range(H):
                        C_cp[i][j]='r'

            for i in range(H):
                if h[i]==1:
                    C_cp[i]='r'
            print(h,w)
            print(C_cp)
            for i in range(H):
                num+=C_cp[i].count('#')
            print(num)
            if num==K:
                ans+=1
                if (all(h)==True or all(w)==True) and (H==1 or W==1):
                    cnt+=1

print(ans-cnt//2)

Submission status: Wrong Answer

Solution code:
h, w, k = map(int, input().split())
cl = [["."]*(w+1)]+ [["."] + list(input()) for _ in range(h)]
print(cl)
hl = []
for c in cl:
    black_num = 0
    for i in c:
        if i == "#":
            black_num += 1
    hl.append(black_num)

wl = []
for j in range(w+1):
    black_num = 0
    for k in range(h+1):
        if cl[k][j] == "#":
            black_num += 1
    wl.append(black_num)
print(hl, wl)

ll = [[0 for j in range(w+1)] for _ in range(h+1)]
for i in range(h+1):
    for j in range(w+1):
        if cl[i][j] != "#":
            ll[i][j] = hl[i] + wl[j]
        else:
            ll[i][j] = hl[i] + wl[j] -1
ans = 0
for l in ll:
    ans += l.count(sum(hl)-k)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools

n_tate, n_yoko, n_kuro = map(int, input().split())

matrix = []
for _ in range(n_tate):
    yoko = [_ for _ in str(input())]
    yoko2 = []
    for char in yoko:
        if char == "#":
            yoko2.append(1)
        else:
            yoko2.append(0)
    matrix.append(yoko2)

matrix2 = np.array(matrix)

tmp = [0, 1]
tate_use_list = list(itertools.combinations_with_replacement(tmp, n_tate))
yoko_use_list = list(itertools.combinations_with_replacement(tmp, n_yoko))
# print("original")
# print(np.array(matrix))
# print()

i = 0
counter = 0
for tate_use in tate_use_list:
    for yoko_use in yoko_use_list:
#         print("tate use:", tate_use)
#         print("yoko_use:", yoko_use)

        matrix3 = matrix2.copy()
        A = np.array(tate_use).reshape(-1, 1)
        B = np.array(yoko_use)

        matrix4 = matrix3 * A * B
#         print(matrix4)
        total = np.sum(matrix4)
        i += 1
#         print(i, total)
        if total == n_kuro:
            counter += 1
            
print(counter)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
h, w, k = map(int, input().split())
C_list = [input() for i in range(h)]
C_num = []
for c_r in C_list:
    r_l = []
    for v in c_r:
        if v == "#": r_l.append(1)
        else: r_l.append(0)
    C_num.append(r_l)
C_num = np.array(C_num)





comb = []
for i in range(h):  # 何行選ぶか
    for j in range(w):  #何列選ぶか
        r = itertools.combinations(range(h), i)# 行をi個選ぶ組み合わせ
        c = itertools.combinations(range(w), j)  # 列をj個選ぶ組み合わせ
        comb.append([r, c])



ans = 0
for R, C in comb:
    for r in R:
        for c in C:
            #print(f"行:{list(r)}")
            #print(f"列:{list(c)}")
            tmp_l = C_num.copy()
            count = 0
            for r_value in r:
                tmp_l[r_value, :] = tmp_l[r_value, :] - 1
            for c_value in c:
                tmp_l[:,c_value] = tmp_l[:,c_value] - 1
            for AAA in tmp_l.flatten():
                if AAA == 1: count += 1


            if count == k: ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
H, W, K = map(int, input().split())
c = []
c.append(['.' for i in range(W + 1)])
for i in range(H):
    temp = '.' + input()
    temp = [char for char in temp]
    c.append(temp)
# print(c)

def count_blacks(c, except_row, except_column):
    count = 0
    for i in range(H + 1):
        if i == except_row: continue

        for j in range(W + 1):
            if j == except_column: continue
            # print(c[i], j)
            if c[i][j] == '#':
                count += 1

    return count


total = H * W
count = 0
for i in range(H + 1):
    for j in range(W + 1):
        num_blacks = count_blacks(c, i, j)
        if num_blacks == K:
            # print(i, j, num_blacks)
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import copy

data = input().split(' ')
H,W,K = int(data[0]),int(data[1]),int(data[2])
#print(H,W,K)
data = []
for i in range(H):
  txt = input()
  bit = []
  for j in range(W):
      bit.append(txt[j])
  data.append(bit)
  
num = 0

for i in range(-1,H):
  for j in range(-1,W):
    cnt = 0
    data2 = copy.deepcopy(data)
    if i >= 0:
      for k in range(W):
      	data2[i][k] = '-'
    if j >= 0:
      for k in range(H):
      	data2[k][j] = '-'
        
    for l in range(H):
      cnt += data2[l].count('#')
    #print(data2,i,j,cnt)
    
    if cnt == K:
      num += 1
      print(num)


for i in range(H):
  cnt = 0
  data2 = copy.deepcopy(data)
  for j in range(i+1):
    if j < H:
      for k in range(W):
          data2[j][k] = '-'
  for l in range(H):
    cnt += data2[l].count('#')
  if cnt == K:
    num+=1   
    
for i in range(W):
  cnt = 0
  data2 = copy.deepcopy(data)
  for j in range(i+1):
    if j < W:
      for k in range(H):
          data2[k][j] = '-'
  for l in range(H):
    cnt += data2[l].count('#')
  if cnt == K:
    num+=1   
    
      
print(num)

Submission status: Wrong Answer

Solution code:
import itertools
import copy
h,w,k = map(int,input().split())
C = [list(input()) for i in range(h)]
ans = 0
for i in range(h+1):
  for j in range(w+1):
    for high in itertools.combinations(range(h),i):
      for width in itertools.combinations(range(w),j):
        C2 = copy.deepcopy(C)
        for hi in high:
          for wi in width:
            C2[hi][wi] = "."
        C2 = list(itertools.chain.from_iterable(C2))
        if C2.count("#") == k:
          ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


mod = 10 ** 9 + 7



h, w, k = LI()
ans = 0
C = SR(h)
for hbit in range(2 ** h):
    for wbit in range(2 ** w):
        ret = 0
        for hi in range(h):
            for wi in range(w):
                if (hbit >> hi) and (wbit >> wi) and C[hi][wi] == "#":
                    ret += 1
        if ret == k:
            ans += 1



print(ans)

Submission status: Wrong Answer

Solution code:

import datetime
from decimal import Decimal, ROUND_DOWN
import heapq
from fractions import gcd
from functools import reduce
from collections import deque
# from math import factorial
import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import statistics
# import numpy as np
# n = int(input())
# n, m, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
#
#  abc = [int(input()) for i in range(5)]
# n = int(input())
h, w, k = list(map(int, input().split()))
# A = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
# s = list(map(int, input().split()))
# b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# ab = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
"""
a.sort(reverse=True)
# print(a)
total = 0
for i in range(n-1):
    total += a[i]
print(total)

"""
c = []
kuro = 0

col_sum = []
row_sum = []
for i in range(h):
    a = input()
    c.append(a)
    ac = a.count('#')
    kuro += ac
    col_sum.append(ac)

for i in range(w):
    cc = 0
    for j in range(h):
        if c[j][i] == "#":
            cc += 1
    row_sum.append(cc)

# print(col_sum)
# print(row_sum)
# print("----------")

if kuro == k:
    print(1)
    exit()

ans = 0
"""
for i in range(h):
    l = list(itertools.combinations(col_sum, i))
    for i in range(len(l)):
        if sum(l[i]) == k:
            ans += 1

for i in range(h):
    l = list(itertools.combinations(row_sum, i))
    for i in range(len(l)):
        if sum(l[i]) == k:
            ans += 1
"""
lll = row_sum+col_sum
for i in range(1, h+w):
    l = list(itertools.combinations(lll, i))
    # print(l)
    for j in range(len(l)):
        _max = max(l[j])
        if _max > k:
            m_count = 0
            tt = _max
            for k in range(i):
                if l[j][k] != _max or(l[j][k] == _max and m_count == 1):
                    tt -= l[j][k]
                elif l[j][k] == _max and m_count == 0:
                    m_count += 1
            if tt == k:
                ans += 1

        elif sum(l[j]) == k:
            ans += 1
# print(lll)
# print(ll)
print(ans)

Submission status: Wrong Answer

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

for i in range(2**H):
  part1 = []
  part1 += board
  for j in range(H):
    if (i>>j)&1:
      part1[j] = ["*"]*W  
  for k in range(2**W):
    part2 = []
    part2 += part1
    for l in range(W):
      if (k>>l)&1:
        for n in range(H):
          part2[n][l] = "*"
    cnt = 0
    for m in part2:
      cnt += m.count("#")
    if cnt == K:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    H,W,K=map(int,input().split())
    gyou=[]
    retu_index=[]
    retu=[0 for _ in range(W)]
    black=0
    for i in range(H):
        s=input()
        gyou.append(s.count("#"))
        tmp=[]
        for j in range(W):
            if s[j]=="#":
                retu[j]+=1
                black+=1
                tmp.append(j)
        retu_index.append(tmp)

    p=black-K
    if p<0:
        print(0)
        sys.exit()
    if p==0:
        print(1)
        sys.exit()

    gyou.extend(retu)
    matrix=gyou

    res=0
    for i in range(pow(2,H+W)):
        n=0
        matrix_=matrix[:]
        for j in range(H+W):
            if (i & (1<<j))!=0:
                if j<H:
                    for k in retu_index[j]:
                        matrix_[H+k]-=1
                n+=matrix_[j]

        if n==p:
            res+=1
    print(res)


if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
h, w, k = map(int, input().split())
c = []
blacks = []
all_b = 0
ans = 0

for i in range(h):
    temp = input()
    temp_list = []
    for t in temp:
        temp_list.append(t)

    c.append(temp_list)
    blacks.append(c[i].count('#'))
    all_b += blacks[i]


c_t = np.array(c).T.tolist()
for i in range(h):
    s = blacks[i]
    for j in range(h):
        if i == j:
            continue
        else:
            if s == blacks[j]:
                ans += 1

for i in range(w):
    temp = c_t[i].count('#')
    for j in range(w):
        if i != j:
            temp_2 = c_t[j].count('#')
            if temp == temp_2:
                ans += 1


for i in range(h):
    s = blacks[i]
    for j in range(w):
        counter_t = c_t[j].count('#')
        if k == all_b - counter_t - s + c[i][j].count('#'):
            print(i+1, j+1)
            ans += 1


print(ans)

Submission status: Wrong Answer

Solution code:
h,w,k=map(int,input().split())
import numpy as np
L=[]
for i in range(h):
    l=list(input())
    for j in range(w):
        if l[j]=='#':
            l[j]=1
        else:
            l[j]=0
    L.append(l)
r=np.asarray(L)
ans=np.sum(r)-k
if ans==0:
    print(1)
    exit()
p=np.sum(r,axis=1)
q=np.sum(r,axis=0)
pp=[]
qq=[]
import itertools as it
for i in range(1,h+1):
    for j in it.combinations([x for x in range(h)],i):
        pp.append(j)
for i in range(1,w+1):
    for j in it.combinations([x for x in range(w)],i):
        qq.append(j)
ok=0
for t in it.product(pp,qq):
    s=0
    for pairs in it.product(t[0],t[1]):
        s += r[pairs[0]][pairs[1]]
    P=0
    for i in t[0]:
        P += p[i]
    Q=0
    for i in t[1]:
        Q += q[i]
    if P+Q-s==ans:
        ok += 1
for i in pp:
    num=0
    for j in i:
        num += p[j]
    if num==ans:
        ok += 1
for i in qq:
    num=0
    for j in i:
        num += q[j]
    if num==ans:
        ok += 1
print(ok)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

H, W, K = map(int, input().split())
if H == 1:
    d = list(map(str, input().split()))
    X = list(d[0])
    black = 0
    for i in range(W):
        if X[i] == "#":
            black += 1
    if K == 0 or K == black:
        print(1)
    else:
        print(0)
elif W == 1:
    X = []
    for i in range(H):
        X.append(input())
    black = 0
    for i in range(H):
        if X[i] == "#":
            black += 1
    if K == 0 or K == black:
        print(1)
    else:
        print(0)
else:
    d = list(map(str, input().split()))
    X = list(d[0])
    for i in range(H - 1):
        d = list(map(str, input().split()))
        d = list(d[0])
        X = np.vstack((X, d))

    black = 0
    for i in range(X.shape[0]):
        for j in range(X.shape[1]):
            if X[i,j] == "#":
                black += 1

    t = 0
    s1 = "0" + str(H) + "b"
    s2 = "0" + str(W) + "b"
    for i in range(2**H):
        for j in range(2**W):

            XX = copy.copy(X)
            black_xx = black
            HH = format(i, s1)
            WW = format(j, s2)

            for ii in range(H):
                if HH[ii] == "1":
                    for iii in range(W):
                        if XX[ii,iii] == "#":
                            black_xx -= 1
                            XX[ii,iii] = "."
            for jj in range(W):
                if WW[jj] == "1":
                    for jjj in range(H):
                        if XX[jjj,jj] == "#":
                            black_xx -= 1
                            XX[jjj,jj] = "."
            if black_xx == K:
                t += 1

    print(t)

Submission status: Wrong Answer

Solution code:
import itertools
import copy

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

all_list = []
for h in range(H):
    h_list = []
    tmp = input()
    for i in range(len(tmp)):
        if(tmp[i] == ('.')):
            h_list.append(0)
        else:
            h_list.append(1)
    all_list.append(h_list)
#print(all_list)

comb_h_tmp = []
comb_w_tmp = []
for h in range(H):
    comb_h_tmp.append(h)
for w in range(W):
    comb_w_tmp.append(w)



cnt = 0

for h in range(H):
    h_comb_list = list(itertools.combinations(comb_h_tmp, h))
    #print('h_comb')
    #print(h_comb_list)
    for h_comb in h_comb_list: #組合せ毎
        all_list_tmp = copy.deepcopy(all_list)
        for h_tmp in h_comb: #組合せの要素毎
            for w in range(W): #選択した行毎
                all_list_tmp[h_tmp][w] = 3
            
            for w in range(W):
                w_comb_list = list(itertools.combinations(comb_w_tmp, w))
                #print('w_comb')
                #print(w_comb_list)
                ##print(w_comb_list)
                for w_comb in w_comb_list: #組合せ毎
                    all_list_tmp_tmp = copy.deepcopy(all_list_tmp)
                    for w_tmp in w_comb: #組合せの要素毎
                        for h_t in range(H): #選択した列毎
                            all_list_tmp_tmp[h_t][w_tmp] = 3
                    #print(all_list_tmp_tmp)
                    cnt_tmp = 0
                    for tmp_h in range(H):
                        cnt_tmp += all_list_tmp_tmp[tmp_h].count(1)
                    if(cnt_tmp == K):
                        cnt += 1
                        #print('answer')

#h選ばなかったとき
for w in range(W):
    w_comb_list = list(itertools.combinations(comb_w_tmp, w))
    #print('w_comb')
    #print(w_comb_list)
    ##print(w_comb_list)
    for w_comb in w_comb_list: #組合せ毎
        all_list_tmp_tmp = copy.deepcopy(all_list)
        for w_tmp in w_comb: #組合せの要素毎
            for h_t in range(H): #選択した列毎
                all_list_tmp_tmp[h_t][w_tmp] = 3
        #print(all_list_tmp_tmp)
        cnt_tmp = 0
        for tmp_h in range(H):
            cnt_tmp += all_list_tmp_tmp[tmp_h].count(1)
        if(cnt_tmp == K):
            cnt += 1
            #print('answer')

#w選ばなかったとき
h_comb_list = list(itertools.combinations(comb_h_tmp, h))
#print('h_comb')
#print(h_comb_list)
for h_comb in h_comb_list: #組合せ毎
    all_list_tmp = copy.deepcopy(all_list)
    for h_tmp in h_comb: #組合せの要素毎
        for w in range(W): #選択した行毎
            all_list_tmp[h_tmp][w] = 3
    
    cnt_tmp = 0
    for h in range(H):
        cnt_tmp += all_list_tmp[h].count(1)
        if(cnt_tmp == K):
            cnt += 1   


#何も選ばなかったとき
cnt_tmp = 0
for h in range(H):
    cnt_tmp += all_list[h].count(1)
    if(cnt_tmp == K):
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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

#Hの組み合わせ生成
h_tmp=[]
for i in range(h):
    h_tmp.append(i)
h_kumi = []
for i in range(h):
    h_kumi.extend(itertools.combinations(h_tmp,i))

#Wの組み合わせ生成
w_tmp=[]
for i in range(w):
    w_tmp.append(i)
w_kumi = []
for i in range(w):
    w_kumi.extend(itertools.combinations(w_tmp,i))

c=[]
for i in range(h):
    c.append(list(input()))
ans = 0
for hk in h_kumi:
    for wk in w_kumi:
        counta=0
        for w_ in range(len(c[0])):
            for h_ in range(len(c)):
                #print(w_,h_)
                #if c[h_][w_]=='#'and h_<hk[0] and h_>hk[1] and w_<wk[0] and w_>wk[1]:
                if c[h_][w_]=='#' and not(h_ in hk) and not(w_ in wk):
                    counta+=1
        #print(counta,hk,wk)
        if counta == k:
            ans+=1

# 何も選ばない
counta=0
for w_ in range(len(c[0])):
    for h_ in range(len(c)):
        #print(w_,h_)
        #if c[h_][w_]=='#'and h_<hk[0] and h_>hk[1] and w_<wk[0] and w_>wk[1]:
        if c[h_][w_]=='#':
            counta+=1
#print(counta,hk,wk)
if counta == k:
    ans+=1


print(ans)
exit()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


mod = 10 ** 9 + 7



h, w, k = LI()
ans = 0
C = SR(h)
for hbit in range(2 ** h):
    for wbit in range(2 ** w):
        ret = 0
        for hi in range(h):
            for wi in range(w):
                if (hbit >> hi) & (wbit >> wi) and C[hi][wi] == "#":
                    ret += 1
        if ret == k:
            ans += 1



print(ans)

Submission status: Wrong Answer

Solution code:
h, w, k = map(int, input().split())
c = []
b = 0
ans = 0
count = [[0] * w for i in range(h)]
for i in range(h):
    ci = input()
    c.append(ci)
    b += ci.count("#")
    for j in range(w):
        count[i][j] += (ci[j] == "#")

for i in range((h + w)**2):
    x, y = [], []
    for j in range(h + w):
        if (i >> j) & 1:
            if j <= h - 1:
                y.append(j)
            else:
                x.append(j - (h - 1) - 1)
    n = 0
    for xi in x:
        n += sum([ci[xi] for ci in count])
    for yi in y:
        n += sum(count[yi])
    for yi in y:
        for xi in x:
            if count[yi][xi]:
                n -= 1
    ans += (b - n == k)
print(ans)