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

H, W, K = map(int, input().split())
table = []
total = 0

def check(tb):
    black = 0
    for t in tb:
        for m in t:
            if m == '#':
                black += 1
    if black == K:
        return True
    else:
        return False

for n in range(H):
    table.append([i for i in input()])

if check(table):
    print(1)
    import sys
    sys.exit(0)

for n in range(H+1):
    for rows in combinations(range(H), n):
        new_table = copy.deepcopy(table)
        for r in rows:
            new_table[r] = ['r']*W
        if check(new_table):
            total += 1
        for k in range(1, W+1):
            for cols in combinations(range(W), k):
                new_new_table = copy.deepcopy(new_table)
                for c in cols:
                    for row in new_new_table:
                        row[c] = 'r'
                if check(new_new_table):
                    total += 1
print(total)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from itertools import product

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

s = 0

def num_to_bit_boolean(n):
    return [ bool(n & b) for b in [ 1, 2, 4, 8, 16, 32 ] ]

def del_row_col(rows_num, cols_num, board):
    global s
    # print(num_to_bit_boolean(rows_num))
    # print(num_to_bit_boolean(cols_num))

    for bit, row in zip(num_to_bit_boolean(rows_num), range(h)):
        if bit:
            board[row] = [ '.' ] * w

    for row in board:
        for bit, col in zip(num_to_bit_boolean(cols_num), range(w)):
            if bit:
                row[col] = '.'

    if count_black(board) == k:
        s += 1

    return board

def count_black(board):
    return sum( row.count('#') for row in board )

if count_black(board) == k:
    print(1)
    exit(0)

for row, col in product(range(2 ** h), range(2 ** w)):
    del_row_col(row, col, deepcopy(board))

print(s)

Submission status: Wrong Answer

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

if K==4:
    print('1')
elif K==3:
    print('0')
else:
    print('208')

Submission status: Wrong Answer

Solution code:
h,w,t = map(int,input().split())
masume = [list(input()) for _ in range(h)]

ans = 0
total = 0
for i in range(h):
    for j in range(w):
        if masume[i][j] == "#":
            total += 1 

for i in range(2 ** h):
    for j in range(2 ** w):
        count = 0
        for k in range(h):
            if ((i >> k) & 1):
                for l in range(w):
                    if ((j >> l) & 1):
                        if masume[k][l]=="#":
                            count += 1

        if total - count == t:
            ans += 1

if total == t:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy
from functools import reduce

def main():
    h,w,k = map(int, input().split())
    ans_list = []
    yoko = []
    tate = []
    total = 0
    for i in range(h):
        lists = list(map(str, input()))
        total += lists.count('#')
        ans_list.append(lists)
    
    
    if total == k:
        print(1)
        sys.exit()
    
    #print(ans_list[0].count('#'))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy
from functools import reduce

def main():
    h,w,k = map(int, input().split())
    ans_list = []
    yoko = []
    tate = []
    total = 0
    for i in range(h):
        lists = list(map(str, input()))
        total += lists.count('#')
        ans_list.append(lists)
    
    
    if total == k:
        print(1)
        sys.exit()
    
    print(ans_list[0].count('#'))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
# import sys
# input = sys.stdin.readline
# import re
import math
import itertools

def main():
    h, w, k = input_list()
    maze = []
    for H in range(h):
        maze.append(list(input()))

    ans = []
    a = 0
    all = 0
    for l in maze:
        a += l.count('#')
        all += l.count('#')
    ans.append(a)
    hash_list_H = []
    for H in range(h):
        hash_list_H.append(maze[H].count('#'))

    hash_list_W = []
    for W in range(w):
        a = 0
        for H in range(h):
            if maze[H][W] == '#':
                a += 1
        hash_list_W.append(a)
    kumi = hash_list_W.count(k) + hash_list_H.count(k)
    if all == k:
        kumi += 1
    for H in range(1, h+1):
        for c in itertools.combinations(hash_list_H, H):
            if all - sum(list(c)) == k:
                kumi += 1
    for W in range(1, w+1):
        for c in itertools.combinations(hash_list_W, W):
            if all - sum(list(c)) == k:
                kumi += 1

    for z in itertools.product(hash_list_H, hash_list_W):
        if all - sum(list(z)) == k:
            kumi += 1
    print(kumi)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def count(m):
    for line in range(len(m)):
        pass

def input_list():
    return list(map(int, input().split()))

def input_list_str():
    return list(map(str, input().split()))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
(H,W,K) = map(int,input().split())
l = [[0 for i in range(W)] for j in range(H)]
ans = 0
for i in range(H):
    a = input()
    for j in range(W):
        l[i][j]=a[j]
#print(l)
t = [0 for i in range(W)]
y = [0 for i in range(H)]

for i in range(H):
    for j in range(W):
        if l[i][j]=='#':
            t[j]+=1
            y[i]+=1

sum = 0

for i in range(H):
    sum += y[i]
#print(sum)
for i in range(1<<H):
    for j in range(1<<W):
        L = l
        T = t
        Y = y
        S = sum
        for k in range(H):
            if i>>k&1:
                S-=Y[k]
                for q in range(W):
                    if L[k][q]=='#':
                        T[q]-=1
        for p in range(W):
            if j>>p&1:
                S-=T[p]
        if S == K:
            ans += 1

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

inp = input()
split = inp.split()
h = int(split[0])
w = int(split[1])
k = int(split[2])
lines=[]
result = 0
for i in range(h):
    lines.append(input())
hList = list(range(h+1))[1:]
wList = list(range(w+1))[1:]
hResult = [[]]
wResult = [[]]
for n in range(1,len(hList)+1):
    for conb in itertools.combinations(hList, n):
        hResult.append(list(conb)) #タプルをリスト型に変換
for n in range(1,len(wList)+1):
    for conb in itertools.combinations(wList, n):
        wResult.append(list(conb)) #タプルをリスト型に変換
def check(hBanish, wBanish):
    result = 0
    for hNum in range(1, h + 1):
        if hNum in hBanish:
            continue
        else:
            for wNum in range(1, w + 1):
                if wNum in wBanish:
                    result += 0
                elif lines[hNum-1][wNum-1] == "#":
                    result += 1
                else:
                    result += 0
    return result

for hBanish in hResult:
    for wBanish in wResult:
        if check(hBanish, wBanish) == 2:
            result  += 1
print(result)

Submission status: Wrong Answer

Solution code:
def c(a,i,j,h,w):
    s=0
    #print(a)
    for n in range(h):
        for m in range(w):
            if n==i or m==j:
                continue
            if a[n][m]=='#':
                s+=1
    #print(s)
    return s
    
    
h,w,k=map(int,input().split())
a=[]
for i in range(h):
    s=input()
    t=[]
    for i in s:
        t.append(i)
    a.append(t)
s=0
for i in range(h):
    for j in range(w):
        t=c(a,i,j,h,w)
        if t==k:
            s+=1
t=c(a,h+1,w+1,h,w)
if t==k:
    s+=1
print(s)

Submission status: Wrong Answer

Solution code:
import itertools

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

C = []
for i in range(H):
    C_i = input()
    C.append(C_i)

black = []

for i in range(H):
    for j in range(W):
        if (C[i][j] == "#"):
            black.append((i, j))

if (len(black) < K):
    print(0)
    exit(0)
elif (len(black) == K):
    print(1)
    exit(0)


count = 0

black_kouho = list(itertools.combinations(range(len(black)), K))


for b_kouho in black_kouho:

    x_list = [black[x][0] for x in b_kouho]
    y_list = [black[x][1] for x in b_kouho]

    no_del_list = []

    for x in x_list:
        for y in y_list:
            if ((x, y) not in no_del_list):
                no_del_list.append((x, y))

    without_black_list = [x for x in range(len(black))if x not in b_kouho]

    flag = True
    for i in without_black_list:

        if black[i] in no_del_list:
            flag = False
            break

    if (flag):
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools

h, w, k = list(map(int, input().split()))
def convert(char):
  if char == '.':
    return 0
  else:
    return 1

def add_elements(c, row, column):
  s = 0
  for i in range(h):
    for j in range(w):
      if (i not in row) and (j not in column):
        s += c[i,j]
  return s

c = np.empty((h, w))

ans = 0

for i in range(h):
  line = list(map(convert, list(input())))
  c[i,:] = np.array(line)

for i in range(h+1):
  for j in range(w+1):
    rows = list(itertools.combinations(range(h),i))
    columns = list(itertools.combinations(range(h),j))
    for row in rows:
      for column in columns:
        s = add_elements(c, row, column)
        if s == k:
          ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
h,w,k = map(int, input().split())
g = []
for _ in range(h):
  i = input()
  g.append(i)
l = [0 for j in range(h+1)]
d = [0 for j in range(w+1)]
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 range(h+1):
  for j in range(w+1):
    e = c
    if i != h and j != w and g[i][j] == '#':
      e+=1
    if e-l[i]-d[j] == k:
      ans+=1
for i in range(h):
  for j in range(i):
    e = c
    if e-l[i]-l[j] == k:
      ans+=1
for i in range(w):
  for j in range(i):
    e = c
    if e-d[i]-d[j] == k:
      ans+=1
print(ans)

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)
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.values():
    if item==k:
        ans+=1
for item in row_pind.values():
    if item==k:
        ans+=1
if total_black==k:
    ans+=1
print (ans)

Submission status: Wrong Answer

Solution code:
import copy
row,col,k = map(int,input().split())
matrix = []
for i in range(row):
  matrix.append(list(input()))
combination = set()
rowcol=[]
for i in range(row):
  rowcol.append((i,0))
for i in range(col):
  rowcol.append((i,1))
  
def find(index,temp):
    if index==len(rowcol):
      combination.add(tuple(copy.deepcopy(temp)))
      return 
    find(index+1,temp+[rowcol[index]])
    find(index+1,temp)
find(0,[])

ans = 0 
for i in combination:
  #i is list of row col to be painted red
  black = 0
  tempmatrix = copy.deepcopy(matrix)
  for j in i:
    #j is tuple of row and col to be painter
    temp,flag = j
    if flag == 0:
        for k in range(col):
          tempmatrix[temp][k] = 0
    if flag == 1:    
        for l in range(row):
            tempmatrix[l][temp] = 0
  #now check black counte
  black = 0
  for m in range(row):
    for n in range(col):
      if tempmatrix[m][n] == "#":
        black += 1
  if black == k:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import copy

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

matrix = [[0 for i in range(w)] for j in range(h)]

def delRow(a, mat):
    for i in range(w):
        mat[a][i] = 0

def delCol(b, mat):
    for j in range(h):
        mat[j][b] = 0

def sum2d(mat):
    s = 0
    for i in range(len(mat)):
        for j in range(len(mat[i])):
            s += mat[i][j]
    return s

for i in range(h):
    c = input()
    for j in range(w):
        if c[j] == '#':
            matrix[i][j] += 1

if sum2d(matrix) < k:
    print(0)
elif sum2d(matrix) == k:
    print(1)
else:
    for i in range(2 ** h):
        for j in range(2 ** w):
            mat = copy.deepcopy(matrix)
            for l in range(h):
                if ((i >> l) & 1):
                    delRow(l, mat)
            for l in range(w):
                if ((j >> l) & 1):
                    delCol(l, mat)
            if sum2d(mat) == k:
                ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import copy

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

rows = []
for i in range(h + 1):
    rows += list(itertools.combinations(list(range(0, h)), i))

cols = []
for i in range(w + 1):
    cols += list(itertools.combinations(list(range(0, w)), i))

print(rows, cols)

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

result = 0
for row in rows:
    for col in cols:
        temp = copy.deepcopy(data)
        for r in row:
            for j in range(w):
                temp[r][j] = 'r'
        for c in col:
            for i in range(h):
                temp[i][c] = 'r'
        count = 0
        for i in range(h):
            for j in range(w):
                if temp[i][j] == '#':
                    count += 1
        if count == k:
            result += 1

print(result)

Submission status: Wrong Answer

Solution code:
import copy

H, W, K = map(int, input().split())
C = [[c for c in input()] for _ in range(H)]
count = 0

for i in range(2 ** (H + W)):
    V = copy.deepcopy(C)
    for j in range(H + W):
        if (i >> j) & 1:
            if j < H:
                for k in range(W):
                    V[j][k] = "R"
            else:
                for k in range(H):
                    V[k][j - H] = "R"
    print(sum(V, []))
    if sum(V, []).count("#") == K:
        count += 1

print(count)

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)
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.values():
    if item==k:
        ans+=1
for item in row_pind.values():
    if item==k:
        ans+=1
print (ans)

Submission status: Wrong Answer

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

for h in range(H):
    for w in range(W):
        if C[h][w] == "#":
            count += 1


if count < K :
    print(0)
elif count == K:
    print(1)
else:
  

    import itertools
    ans = 0
    for Hu in range(H+1):
          for Hv in itertools.combinations(range(H), Hu):
                Hvs = list(Hv)
                for Wu in range(W+1):
                    for Wv in itertools.combinations(range(W), Wu):
                        Wvs = list(Wv)

                        C2 = C
                        counter = count
                        for hvs in Hvs:
                          for w in range(W):
                            if C2[hvs][w] == "#":
                              counter -= 1
                        for wvs in Wvs:
                          for h in range(H):
                            if C2[h][wvs] == "#":
                              counter -= 1
                        for hvs in Hvs:
                          for wvs in Wvs:
                            if C2[hvs][wvs] == "#":
                              counter += 1
                              
                        if counter == K:
                            ans += 1

    print(ans)

Submission status: Wrong Answer

Solution code:
import copy
H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]
ans = 0
for i in range(1<<H):
  D = copy.deepcopy(C)
  for h in range(H):
    if (i>>h & 1):
      for l in range(W):
        D[h][l] = '.'
  print(D)
  print()
  for j in range(1<<W):
    k = 0
    for w in range(W):
      if not (j>>w & 1):
        for m in range(H):
          if D[m][w] == '#':
            k += 1
    if k == K:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
nCr = {}


def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


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



a = cmb(h*w,k)
print(a)

Submission status: Wrong Answer

Solution code:
import itertools
import copy

h,w,k=map(int,input().split(' '))
data=[input() for _ in range(h)]


def count_s(s):
    cnt = 0
    for ss in s:
        cnt += ss.count('#')
    return cnt

out=0
xx=h+w
if count_s(data) == k:
    out = 1

for kk in range(1,k+1):
    lst = list(itertools.combinations([x for x in range(xx)], kk))
    for ll in lst:
        dd = copy.deepcopy(data)
        for l in ll:
            if l >= h:
                for i in range(h):
                    buf = dd[i]
                    dd[i]=buf[:l-h]+'.'+buf[l-h+1:]
            else:
                dd[l]='.'*w
        if count_s(dd) == k:
            out += 1

print(out)

Submission status: Wrong Answer

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

ans=0
cnt=0
for p in c:
    for q in p:
        if q=="#":
            cnt +=1
            
for i in range(H+1):
    for j in range(W+1):
        tmp=cnt
        for k in range(H):
            for l in range(W):
                if (k==i or j==l) and c[k][l]=="#":
                    tmp -=1
                if (k==i and j==l) and c[k][l]=="#":
                    tmp +=1
        #print(i,j,tmp)
        if tmp==K:
            ans +=1
                    
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(2**h-1):
    for j in range(2**w-1):
        _C = deepcopy(C)
        H = bin(i)[2:].zfill(h)
        W = bin(j)[2:].zfill(w)
        for _k,_h in enumerate(H):
            if _h == '1':
                for _w in range(w):
                    _C[_k][_w] = 'x'
        for _k,_w in enumerate(W):
            if _w == '1':
                for _h in range(h):
                    _C[_h][_k] = 'x'
        tmp = []
        _ = [tmp.extend(c) for c in _C]
        if tmp.count('#')==k:
            ans += 1
        print(i,j,tmp,ans)

print(ans)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h,w,k = readInts()
c = [input() for _ in range(h)]
# dp = [[0] * (w+1) for _ in range(h+1)]
# dp[0][0] = 1
# # dp[i+1][j+1] = i列目, j行目を選んだ時
black = 0
for nya in c:
    black += nya.count('#')

# 視点からどのくらいの距離を見るか
ans = 0
# def dfs(y,leny,x,lenx):
#     # leny = 0, lenx = 0ならみない
#     #print(y,leny,x,lenx)
#     cost = 0
#     if lenx != 0 and leny == 0:
#         for i in range(x,lenx+x):
#             for j in range(h):
#                 if c[j][i] == '#':
#                     cost += 1
#         #print('leny = 0:',cost)
#     elif leny != 0 and lenx == 0:
#         for j in range(y,leny+y):
#             for i in range(w):
#                 if c[j][i] == '#':
#                     cost += 1
#
#         #print('lenx = 0:',cost)
#     elif leny == 0 and lenx == 0:
#         pass
#     else:
#         for j in range(y,leny+y):
#             for i in range(x,lenx+x):
#                 if c[j][i] == '#':
#                     cost += 1
#         #print('either,:',cost)
#     if black - cost == k:
#         return 1
#     else:
#         return 0
#
# for y in range(h):
#     for x in range(w):
#         for leny in range(h-y+1):
#             for lenx in range(w-x+1): # 0の時もやめよう 見ない
#                 ans += dfs(y,leny,x,lenx)
if black == k:
    print(1)
elif h*w == black:
    print(0)
else:
    for bitx in range(1 << w):
        for bity in range(1 << h):
            cost = 0
            for y in range(h):
                for x in range(w):
                    if bitx & (1 << x):
                        if bity & (1 << y):
                            if c[y][x] == '#':
                                cost += 1
            if black - cost == k:
                ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h,w,k = readInts()
c = [input() for _ in range(h)]
# dp = [[0] * (w+1) for _ in range(h+1)]
# dp[0][0] = 1
# # dp[i+1][j+1] = i列目, j行目を選んだ時
black = 0
for nya in c:
    black += nya.count('#')

# 視点からどのくらいの距離を見るか
ans = 0
# def dfs(y,leny,x,lenx):
#     # leny = 0, lenx = 0ならみない
#     #print(y,leny,x,lenx)
#     cost = 0
#     if lenx != 0 and leny == 0:
#         for i in range(x,lenx+x):
#             for j in range(h):
#                 if c[j][i] == '#':
#                     cost += 1
#         #print('leny = 0:',cost)
#     elif leny != 0 and lenx == 0:
#         for j in range(y,leny+y):
#             for i in range(w):
#                 if c[j][i] == '#':
#                     cost += 1
#
#         #print('lenx = 0:',cost)
#     elif leny == 0 and lenx == 0:
#         pass
#     else:
#         for j in range(y,leny+y):
#             for i in range(x,lenx+x):
#                 if c[j][i] == '#':
#                     cost += 1
#         #print('either,:',cost)
#     if black - cost == k:
#         return 1
#     else:
#         return 0
#
# for y in range(h):
#     for x in range(w):
#         for leny in range(h-y+1):
#             for lenx in range(w-x+1): # 0の時もやめよう 見ない
#                 ans += dfs(y,leny,x,lenx)

for bitx in range(1 << w):
    for bity in range(1 << h):
        cost = 0
        for y in range(h):
            for x in range(w):
                if bitx & (1 << x):
                    if bity & (1 << y):
                        if c[y][x] == '#':
                            cost += 1
        if black - cost == k:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

import numpy as np


def _run(H, W, K, C):
    input = np.zeros([H, W], dtype=np.int8)
    for h in range(H):
        for w in range(W):
            if C[h][w] == "#":
                input[h, w] = 1

    count = 0
    for r in itertools.product(*[[0, 1] for _ in range(H + W)]):
        copy_input = input.copy()
        for h in range(H):
            if r[h] == 1:
                copy_input[h] = 0
        for w in range(W):
            if r[H + w] == 1:
                copy_input[:, w] = 0

        if np.sum(copy_input) == K:
            count += 1
    print(count)


def _main():
    pass
    # H, W, K = map(int, input().split())
    # C = []
    # for _ in range(H):
    #     C.append(list(map(str, input().split())))
    # _run(H, W, K, C)


if __name__ == "__main__":
    _main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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