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:
import itertools
import copy

def red_gyou(c, gyou, W):
  for i in range(W):
    c[gyou][i] = 0
    
def red_retsu(c, retsu, H):
  for j in range(H):
    c[j][retsu] = 0
    
def blacks(c, H):
  black = 0
  for i in range(H):
    black += sum(c[i])
  return black

H, W, K = map(int, input().split())
c = []
for i in range(H):
  gyou = []
  colors = input()
  for color in colors:
    if color == '#':
      gyou.append(1) # black
    else:
      gyou.append(0) # white
  c.append(gyou)
tate = list(range(H))
yoko = list(range(W))
answer = 0

for i in range(H+1):
  red_tate = list(itertools.combinations(tate, i))
  for j in range(W+1):
    red_yoko = list(itertools.combinations(yoko, j))
    if not i and j:
      for ry in red_tate:
        cc = copy.deepcopy(c)
        for jj in ry:
          red_retsu(cc, jj, W)
        if blacks(cc, H) == K:
          answer += 1
      continue
    elif i and not j:
      for rt in red_yoko:
        cc = copy.deepcopy(c)
        for ii in rt:
          red_gyou(cc, ii, H)
        if blacks(cc, H) == K:
          answer += 1
      continue
    elif not i and not j:
      continue
    for rt in red_tate:
      for ry in red_yoko:
        cc = copy.deepcopy(c)
        for ii in rt:
          red_gyou(cc, ii, W)
        for jj in ry:
          red_retsu(cc, jj, H)
        if blacks(cc, H) == K:
          answer += 1
print(answer)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

# from math import gcd
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

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

def calc(lis):
    global C, K

    c = copy.copy(C)

    for i in lis:
        if i // 10 == 1:
            c[i%10-1] = "-" * W
        else:
            for j in range(H):
                tmp = list(c[j])
                tmp[i-1] = "-"
                c[j] = "".join(tmp)

    ct = 0
    for i in c:
        a = Counter(i)
        ct += a["#"]
    
    if ct == K:
        return 1
    return 0
                
count = 0
lis = list(range(1, W + 1)) + list(range(10, 10 + H + 1))

ret = 0
for i in range(H+W):
    for com in list(combinations(lis, i)):
        ret += calc(com)

print(ret)

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:
from collections import Counter
import copy
from itertools import combinations


def A(x):
  return 1000 - x % 1000 if x % 1000 != 0 else 0


def B(n, ss):
  keys_values = Counter(ss)
  orders = ['AC', 'WA', 'TLE', 'RE']
  for order in orders:
    if order in keys_values:
      print("{} x {}".format(order, keys_values[order]))
    else:
      print("{} x {}".format(order, 0))


def C(h, w, k, g):

  def _get_num_black(c_list, r_list):
    num_black = 0
    for i in range(h):
      if i in r_list:
        continue
      for j in range(w):
        if j in c_list:
          continue
        num_black += (1 if g[i][j] == '#' else 0)
    return num_black

  num_choice = 0
  for i in range(k + 1):
    for j in range(k - i + 1):
      comb_c = list(combinations(range(w), j))
      comb_r = list(combinations(range(h), i))
      for c_list in comb_c:
        for r_list in comb_r:
          num_black = _get_num_black(c_list, r_list)
          if num_black == k:
            num_choice += 1
          # print(h, i, comb_r, w, j, comb_c, num_black, k)
  return num_choice


def main():
  h, w, k = map(int, input().split())
  g = []
  for i in range(h):
    g.append(input())
  print(C(h, w, k, g))


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

# from math import gcd
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

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

def calc(lis):
    global C, K

    c = copy.copy(C)

    for i in lis:
        if i // 10 == 1:
            c[i%10-1] = "-" * W
        else:
            for j in range(H):
                tmp = list(c[j])
                tmp[i-1] = "-"
                c[j] = "".join(tmp)

    ct = 0
    for i in c:
        a = Counter(i)
        ct += a["#"]
    
    if ct == K:
        print(lis, c)
        return 1
    return 0
                
count = 0
lis = list(range(1, W + 1)) + list(range(10, 10 + H + 1))

ret = 0
for i in range(H+W):
    for com in list(combinations(lis, i)):
        ret += calc(com)

print(ret)

Submission status: Wrong Answer

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

grid.insert(0, ["."] * (W + 1))

for i in range(H+1):
    for j in range(W+1):
        cnt = 0
        grid_copy = copy.deepcopy(grid)
        grid_copy[i] = ["|"] * (W+1)
        for k in range(H+1):
            grid_copy[k][j] = "|"

        for l in range(H+1):
            for m in range(W+1):
                if grid_copy[l][m] == "#":
                    cnt += 1

        if cnt == K:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
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 == lhs:
            continue
        for j in range(W):
            if j == 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()

# 行列
for i in range(H + 1):
    for j in range(W+1):
        cnt = countData(i, j)
        if (cnt == K):
            ans += 1

# 行行
for i in range(H):
    for j in range(i+1, H):
        cnt = countRow(i, j)
        if (cnt == K):
            ans += 1

# 列列
for i in range(W):
    for j in range(i+1, W):
        cnt = countCol(i, j)
        if (cnt == K):
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  H, W, K = map(int, input().split())
  c = [[0 for j in range(W)] for i in range(H)]
  import numpy as np
  c = np.zeros((H, W), dtype=np.str)
  for i in range(H):
    c[i] = list(input())
    
  u, counts = np.unique(c, return_counts=True)
  if counts[0] == K:
    print(0)
    return

main()

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W, K = map(int, input().split())
zu = np.zeros((H, W), dtype=int)

for h in range(H):
    zu[h, :] = (np.array(list(input())) == '#')

MAXX = 2**(H+W)
ans = 0
if np.sum(zu) == K:
    ans += 1

for c in range(MAXX):
    zu1 = np.copy(zu)
    for h in range(H):
        if (c & (1<<h)) > 0:
            zu1[h] = 0
    for w in range(W):
        if (c & (1<<(H+w))) > 0:
            zu1[:, w] = 0
    if np.sum(zu1) == K:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

def c2i(c):
    if c == '.':
        return 0
    elif c == '#':
        return 1

m = []
lines = []
rows = [0] * W
total = 0

for idx in range(H):
    c = input()
    m.append([*c])

    black_num = c.count('#')
    total += black_num
    lines.append(black_num)
    rows = [row + c2i(c[i]) for i, row in enumerate(rows)]

patterns = []
count = 0

for yy in itertools.product([0, 1], repeat=(H)):
    for xx in itertools.product([0, 1], repeat=(W)):
        sub = 0
        r = 0
        l = 0
        for idx_l, line in enumerate(yy):
            if line == 1:
                l += lines[idx_l]

        for idx_r, row in enumerate(xx):
            if row == 1:
                r += rows[idx_r]

        #print(l, r, sub)
        black_num = total - (l + r) - sub
        if black_num == K:
            patterns.append([xx, yy])
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

H, W, K = map(int, input().split())
if H == 1:
    print("A")
elif W == 1:
    print("B")
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 numpy as np

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

result = 0

n_c = np.array(c)

for y in itertools.product([0,1], repeat = h):
    for x in itertools.product([0,1], repeat = w):
        # print(y, x)
        n_c2 = np.array(c)
        for i, y2 in enumerate(y):
            if y2 == 1:
                n_c2[i] = 'R'
        for i, x2 in enumerate(x):
            if x2 == 1:
                n_c2[:,i] = 'R'
        # print(n_c2)
        m = np.count_nonzero(n_c2 == '#')
        if k == m:
            result += 1

Submission status: Wrong Answer

Solution code:
inp = list(map(int,input().split()))
row=inp[0]
col=inp[1]
k=inp[2]
row_b=[]
col_b=[]
color=[]
for i in range(row):
    s=input()
    color.append(s)
    this=0
    for j in range(col):
        if s[j]=='#':
            this+=1
    row_b.append(this)
if row==col==1:
    if k==0:
        if color[0][0]=='#':
            print (3)
        else:
            print (4)
    else:
        if color[0][0]=='#':
            print (1)
        else:
            print (0)
else:
    for i in range(col):
        this=0
        for j in range(row):
            if color[j][i]=='#':
                this+=1
        col_b.append(this)
    total_black=sum(col_b)
    from collections import Counter
    row_pind=Counter([])
    a=1<<row
    for i in range(1,a):
        m=i
        ind=row-1
        tot=0
        arr=[]
        while m>0:
            if m&1:
                arr.append(ind)
                tot+=row_b[ind]
            ind-=1
            m=m>>1
        row_pind[tuple(arr)]=tot
    col_pind=Counter([])
    a=1<<col
    for i in range(1,a):
        m=i
        ind=col-1
        tot=0
        arr=[]
        while m>0:
            if m&1:
                arr.append(ind)
                tot+=col_b[ind]
            ind-=1
            m=m>>1
        col_pind[tuple(arr)]=tot
    c=list(col_pind.keys())
    r=list(row_pind.keys())
    ans=0
    for i in range(len(r)):
        for j in range(len(c)):
            x=col_pind[c[j]]+row_pind[r[i]]
            if x<k:
                continue
            else:
                z=0
                for p in r[i]:
                    for q in c[j]:
                        if color[p][q]=='#':
                            z+=1
                if total_black-(x-z)==k:
                    ans+=1
    for item in col_pind.keys():
        z=col_pind[item]
        if z==k and len(item)!=col:
            ans+=1
    for item in row_pind.keys():
        z=row_pind[item]
        if z==k and len(item)!=row:
            ans+=1
    if total_black==k:
        ans+=1
    print (ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations as itemcombi
H,W,K = map(int,input().split())
C = list([i for i in input()] for _ in range(H))
B = C[:]
for i in range(H+1):
    print(B,"BBBBBBBBB")
    T = list(itemcombi(range(H), i))
    for j in T:
        for k in range(len(j)):
            for l in range(W):
                B[j[k]][l] = "!"
    print(B)
    print("!!!!!!!!!!!!!!!!!")
    D = B[:]
    for m in range(W+1):
        T = list(itemcombi(range(W), m))
        #print(T,"TWW")
        for j in T:
            for k in range(len(j)):
                for l in range(H):
            #        print(B[l][j[k]],l,j[k])
                    B[l][j[k]] = "?"

           # print("--------------")
            B = D[:]
            print(B,"-----------")
    B = C[:]

Submission status: Wrong Answer

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

C = [0 for h in range(H)]
n = [0 for h in range(H)]
m = [0 for w in range(W)]

count = 0
ans = 0

for h in range(H):
  C[h] = list(input())
  
for h in range(H):
  for w in range(W):
    if C[h][w] == "#":
      count += 1
      n[h] += 1
      m[w] += 1
      
for h in range(H):
  for w in range(W):
    if C[h][w] != "#":
      if count - (n[h]+m[w]) == K:
        ans += 1
    elif C[h][w] == "#":
      if count - (n[h]+m[w]-1) == K:
        ans += 1
    if count - n[h] == K:
      ans += 1
    elif count - m[w] == K:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,K = map(int,input().split())
masu = list(map(str,input().split()))
Gyou,Retu = [],[]
for i in range(2**H):
  gyou = [0]*H
  for j in range(H):
    if((i >> j)%1):
      gyou[H-1-j] = 1
    Gyou.append(gyou)
for i in range(2**W):
  retu = [0]*W
  for j in range(H):
    if((i >> j)%1):
      retu[W-1-j] = 1
    Retu.append(retu)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import numpy as np
# t = [1, 2, 3, 4]
# a = list(combinations(t, 1))
# print(a[0][0] == 1)
# print(t[a[0]])

h, w, k = map(int, input().split())
c_m = [list(input()) for _ in range(h)]
c_m = np.array(c_m)
result = 0
for i in range(1, h+1):
    chs = list(combinations(range(h), i))
    for ch in chs:
        c_1 = c_m.copy()
        for ch_i in ch:
            c_1[ch_i] = 'r'
        for j in range(1, w+1):
            whs = (combinations(range(w), j))
            for wh in whs:
                c_2 = c_1.copy()
                for wh_i in wh:
                    c_2[:,wh_i] = 'r'
                if np.sum(c_2=='#') == k: result += 1


for i in range(1, h+1):
    chs = list(combinations(range(h), i))
    for ch in chs:
        c_1 = c_m.copy()
        for ch_i in ch:
            c_1[ch_i] = 'r'
        if np.sum(c_1=='#') == k: result += 1

for i in range(1, w+1):
    chs = list(combinations(range(w), i))
    for ch in chs:
        c_1 = c_m.copy()
        for ch_i in ch:
            c_1[:,ch_i] = 'r'
        if np.sum(c_1=='#') == k: result += 1

print(result)

Submission status: Wrong Answer

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

cs = []
for i in range(h):
    cs.append(list(input()))

# print(cs)

hpatterns = []
for i in range(h + 1):
    hpatterns += list(itertools.combinations(range(h), i))
wpatterns = []
for i in range(w + 1):
    wpatterns += list(itertools.combinations(range(w), i))

# print(hpatterns)
# print(wpatterns)

c = 0
for hpattern in hpatterns:
    for wpattern in wpatterns:
        black = 0
        cs2 = copy.deepcopy(cs)
        for pi in range(len(hpattern)):
            cs2[pi] = ['' for k in range(w)]

        for pj in range(len(wpattern)):
            for s in range(len(cs2)):
                # print(pj, s)
                cs2[s][pj] = ''
        # print(hpattern, wpattern, cs2)
        for s in cs2:
            black += s.count('#')

        if black == k:
            c += 1

print(c)

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 and (H==1 or W==1):
                    cnt+=1

print(ans-cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools

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

bw_map = []
row_list = []
for _ in range(H):
    tmp = list(input())
    bw_map.append(tmp)

bw_map = np.array(bw_map)
score = np.sum(bw_map=="#")


result = 0
if score==K:
    print(1)
elif score==0:
    for h in range(H):
        for w in range(W):
            h_args = list(itertools.combinations(list(range(H)), h))
            w_args = list(itertools.combinations(list(range(W)), w))
            print(h_args)
            print(w_args)

elif score<=K:
    print(0)
else:
    score = 100000
    for h in range(H):
        for w in range(W):
            if h==0 and w==0:
                continue
            h_args = list(itertools.combinations(list(range(H)), h))
            w_args = list(itertools.combinations(list(range(W)), w))
            for hs in h_args:
                for ws in w_args:
                    tmphs=hs
                    tmpws=ws
                    hs = list(hs)
                    ws = list(ws)
                    hs = list(set(list(range(H)))-set(hs))
                    ws = list(set(list(range(W)))-set(ws))
                    if len(hs)==0:
                        score = np.sum(bw_map[:, ws]=="#")
                    elif len(ws)==0:
                        score = np.sum(bw_map[hs, :]=="#")
                    else:
                        tmp = bw_map[hs]
                        tmp = tmp[:, ws]
                        score = np.sum(tmp=="#")

                    if score == K:
                        result+=1
    print(result)

Submission status: Wrong Answer

Solution code:
H,W,K=map(int,input().split())
c=[]
#.white,#black
sumblack=0
ans=0
glist=[]
rlist = [0 for _ in range(W)]

for i in range(H):
    g=list(input())
    glist+=[g.count("#")]
    for j in range(W):
        if g[j]=="#":
            rlist[j]+=1
    sumblack+=g.count("#")
    g.append(".")
    c.append(g)
c+=[["." for _ in range(W+1)]]

glist.append(0)
rlist.append(0)
for i in range(H+1):
    for j in range(W+1):
        if c[i][j]=="#":
            cor=1
        else:
            cor=0
        if sumblack - glist[i] - rlist[j] + cor == K:
            ans+=1
for i in range(H):
    for j in range(i+1,H):
        if sumblack - glist[i] - glist[j] == K:
            ans+=1
for i in range(W):
    for j in range(i+1,W):
        if sumblack - rlist[i] - rlist[j] == K:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
h,w,k = map(int,input().split())
c = [[0]*w for _ in range(h)] #[h][w]
for i in range(h):
    f = input()
    for j in range(w):
        if f[j]=='#':
            c[i][j]+=1
            
yoko = []
tate = [0]*w
for i in range(h):
    yoko.append(sum(c[i]))
    for j in range(w):
        tate[j]+=c[i][j]
aaa = sum(yoko)
if aaa==k:
    print(1)
    exit()
    
ans = 0
for i in range(2**h-1):
    for j in range(2**w-1):
        cnt=0
        check1=[]
        check2=[]
        for n in range(h):
            if (i>>n)&1:
                cnt+=yoko[n]
                check1.append(n)
        for m in range(w):
            if (j>>m)&1:
                cnt+=tate[m]
                check2.append(m)
        for n in check1:
            for m in check2:
                if c[n][m]==1:
                    cnt-=1
        if aaa-cnt==k:
            ans+=1
        

print(ans)

Submission status: Wrong Answer

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

d = 0
kk = 0
g= []
for i in range(2 ** h):
    gg=[]
    for j in range(h):
        if ((i>>j) &1):
            gg.append(j)
    g.append(gg)
import copy
gb = copy.deepcopy(g)
for lis in g:
    ii = lis
    for lisj in gb:
        jj = lisj

        for i in range(h):
            if i in ii:
                continue
            for j in range(w):
                if j in jj:
                    continue
                if c[i][j]=='#':
                    kk+=1

        if kk==k:
            d+=1
        kk = 0
print(d)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools

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

bw_map = []
row_list = []
for _ in range(H):
    tmp = list(input())
    bw_map.append(tmp)

bw_map = np.array(bw_map)
score = np.sum(bw_map=="#")


result = 0
if score==K:
    print(1)
elif score<K:
    print(0)
else:
    score = 100000
    for h in range(H):
        for w in range(W):
            if h==0 and w==0:
                continue
            h_args = list(itertools.combinations(list(range(H)), h))
            w_args = list(itertools.combinations(list(range(W)), w))
            for hs in h_args:
                for ws in w_args:
                    tmphs=hs
                    tmpws=ws
                    hs = list(hs)
                    ws = list(ws)
                    hs = list(set(list(range(H)))-set(hs))
                    ws = list(set(list(range(W)))-set(ws))
                    if len(hs)==0:
                        score = np.sum(bw_map[:, ws]=="#")
                    elif len(ws)==0:
                        score = np.sum(bw_map[hs, :]=="#")
                    else:
                        tmp = bw_map[hs]
                        tmp = tmp[:, ws]
                        score = np.sum(tmp=="#")

                    if score == K:
                        result+=1
    print(result)

Submission status: Wrong Answer

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

ans=0
fh = list(product([1,0],repeat=H))
fw = list(product([1,0],repeat=W))

for s in fh:
    for t in fw:        
        tmp=0
        for i in range(H):
            for j in range(W):
                if c[i][j]=="#" and (s[i] or t[j]):
                    tmp +=1                
        if tmp==K:
            ans +=1
            #print(s,t)
                    
print(ans)