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:
H, W, K = map(int, input().split())
M = [input() for _ in range(H)]
ans = 0
for h in range(1 << H):
    hse = set()
    for hh in range(H):
        if h&(1<<hh):
            hse.add(hh)
    for w in range(1 << W):
        cnt = 0
        wse = set()
        for ww in range(W):
            if w&(1<<ww):
                wse.add(ww)
        for hhh in range(H):
            for www in range(W):
                if hhh in hse: continue
                if www in wse: continue
                if M[hhh][www] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
C = []
for i in range(H):
  cs = input()
  C.append(cs)
s = set()
for i in range(H):
  for j in range(W):
    if C[i][j] == "#":
      s.add((i, j))
r = 0
for n in range(1<<(H+W)):
  si = set()
  sj = set()
  for i in range(H+W):
    if n&(1<<i) != 0:
      if i < H:
        si.add(i)
      else:
        sj.add(i-H)
  k = 0
  for i, j in s:
    if (i not in si) and (j not in sj):
      k += 1
  if k == K:
    r += 1
print(r)

Submission status: Accepted

Solution code:
import copy
H,W,K = map(int, input().split())
board = [0]*H

def retunuru(x):
    for j in range(H):
        if ((x>>j)&1):
            new_board_num[j] = [5]*W

def gyonuru(y):
    for l in range(W):
        if ((y>>l)&1):
            for a in range(H):
                new_board_num[a][l]=5

for i in range(H):
    board[i] = input()

board_num = [[0]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        if board[i][j]==".":
            board_num[i][j] = 0
        else:
            board_num[i][j] = 1


ans = 0
new_board_num = copy.deepcopy(board_num)
for i in range(2**H):
    total = 0
    for k in range(2**W):
        retunuru(i)
        gyonuru(k)
        for x in range(H):
            for y in range(W):
                if new_board_num[x][y]==1:
                    total+=1
        #print(i,k)
        #print(new_board_num)
        #print(total)

        if total == K:
            ans +=1
            #print("ok")
        new_board_num = copy.deepcopy(board_num)

        total = 0
print(ans)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
C = []
sum = 0
count = 0
ans = 0
for i in range(H):
    c = input()
    # for j in range(len):
    C.append(c)
    sum += c.count("#")

for h in range(2 ** H):
    for w in range(2 ** W):
        for h2 in range(H):
            if (h >> h2) & 1:
                continue
            for w2 in range(W):
                if (w >> w2) & 1:
                    continue
                if C[h2][w2] == "#":
                    count += 1
        if count == K:
            ans += 1
        count = 0

print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
c = []
for _ in range(h):
    c.append(list(input()))
def calc_black_cnt(maskR, maskC):
    cnt = 0
    for i in range(h):
        for j in range(w):
            if maskR>>i & 1 == 0 and maskC>>j & 1 == 0 and c[i][j] == '#':
                cnt += 1
    return cnt
ans = 0
for maskR in range(1<<h):
    for maskC in range(1<<w):
         if calc_black_cnt(maskR, maskC) == k:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
H,W,K = list(map(int,input().split()))
c = []
for i in range(H):
    c.append(list(input()))
ans = 0
H_pattern,W_pattern = 2**H,2**W
for i in range(0,H_pattern):
    for j in range(0,W_pattern):
        H_active_arr,W_active_arr=list(bin((H_pattern-1)&i)[2:].zfill(H)),list(bin((W_pattern-1)&j)[2:].zfill(W))
        count = 0
        for k,arr in enumerate(c):
            for l,item in enumerate(arr):
                if H_active_arr[k] == "1" and W_active_arr[l] == "1" and item == "#":
                    count += 1
        if count == K:
            ans += 1
print(ans)

Submission status: Accepted

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

import itertools
import numpy as np

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

c = [list(str(input())) for _ in range(h)]
# print(c)

c = np.array(c)

ans = 0
for h_flag in itertools.product([0, 1], repeat=h):
    h_flag = [i for i, j in enumerate(h_flag) if j == 1]
    for w_flag in itertools.product([0, 1], repeat=w):
        w_flag = [i for i, j in enumerate(w_flag) if j == 1]
        # print()
        c_ = c[:]
        c_ = np.take(c_, h_flag, axis=0)
        # print(c_)
        c_ = np.take(c_, w_flag, axis=1)
        # print(c_)

        if np.sum(c_ == "#") == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    h, w, k = nm()
    ans = 0
    C = [ns() for _ in range(h)]

    def calc(bi, bj):
        res = 0
        for i in range(h):
            for j in range(w):
                if bi & (1 << i) and bj & (1 << j) and C[i][j] == '#':
                    res += 1
        return res


    for bi in range(1 << h):
        for bj in range(1 << w):
            ans += (calc(bi, bj) == k)
    print(ans)
    return

solve()

Submission status: Accepted

Solution code:
#n=int(input())
import copy
h,w,K=map(int,input().split())
#l=list(map(int,input().split()))
l=[list(input()) for i in range(h)]
rowl=[]
coll=[]

def count_black(l2d):
    res=0
    for l in l2d:
        res+=l.count('#')
    return res

for i in range(2**h):
    temp=[]
    for k in range(h):
        if ((i >> k) & 1):#二進数iの下から数えてj桁目が1か否か
            temp.append(k)
    rowl.append(temp)
for j in range(2**w):
    temp=[]
    for k in range(w):
        if ((j >> k) & 1):
            temp.append(k)
    coll.append(temp)

count=0
# 全探索
rowall=["r" for i in range(w)]
for row in rowl:
    for col in coll:
        test=copy.deepcopy(l)
        for i in row:
            test[i]=rowall
        for j in col:
            for i in range(h):
                test[i][j]='r'
        if count_black(test)==K:
            count+=1

print(count)

Submission status: Accepted

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

c = [input() for _ in range(H)]

ans = 0
for h in range(1 << H):
    for w in range(1 << W):
        k = 0
        for i in [i for i in range(H) if not h & (1 << i)]:
            for j in [j for j in range(W) if not w & (1 << j)]:
                if c[i][j] == "#":
                    k += 1
        if k == K:
            ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
for row in range(2 ** h):
    for col in range(2 ** w):
        a = [[0 for _ in range(w)] for _ in range(h)]
        for i in range(h):
            for j in range(w):
                if row & (1 << i) or col & (1 << j):
                    a[i][j] = '.'
                else:
                    a[i][j] = c[i][j]
        black = 0
        for line in a:
            for cell in line:
                if cell == '#':
                    black += 1
        if black == k:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from copy import deepcopy

def readinput():
    h,w,k=list(map(int,input().split()))
    c=[]
    for _ in range(h):
        l=list(input())
        c.append(l)
    return h,w,k,c

def printC(c):
    for l in c:
        print(l)

def main(h,w,k,c):
    ans=0
    for g in range(2**h):
        for r in range(2**w):
            cc=deepcopy(c)
            for i in range(h):
                b=2**i
                if g & b == b:
                    for j in range(w):
                        cc[i][j]='*'
            for j in range(w):
                b=2**j
                if r & b == b:
                    for i in range(h):
                        cc[i][j]='*'
            #print(g,r)
            #printC(cc)
            count=0
            for i in range(1,h+1):
                for j in range(1,w+1):
                    if cc[i-1][j-1]=='#':
                        count+=1
            if count==k:
                ans+=1

    return ans

if __name__=='__main__':
    h,w,k,c=readinput()
    ans=main(h,w,k,c)
    print(ans)

Submission status: Accepted

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

ans = 0
for n in range(1 << h):
  for m in range(1 << w):
    count = 0
    for i in range(h):
      for j in range(w):
        if n >> i & 1:
          continue
        if m >> j & 1:
          continue
        if c[i][j] == '#':
          count += 1
    if count == k:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
h,w,k=map(int,input().split())
lis=[[0 for i in range(6)]for j in range(6)]
for i in range(h):
  tmp=input()
  for j in range(w):
    if(tmp[j]=="#"):
      lis[i][j]=1

ans=0
for i in range(2**h):
  for j in range(2**w):
    tmp=0
    hoge="{:0>{}b}".format(i, 6)[::-1]
    huga="{:0>{}b}".format(j, 6)[::-1]
    for a in range(6):
      for b in range(6):
        if(hoge[a]=="0" and huga[b]=="0"):
          if(lis[a][b]==1):
            tmp+=1
            
    if(tmp==k):
      ans+=1
      #print(hoge,huga)
      
print(ans)

Submission status: Accepted

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

ans=0
for i in range(2**H): # 全てのビットを生成するループ
    Bit_i = list(range(1,H+1)) # [1,1,1...]の形でビットを初期化したリスト
    for k in range(H): #　いい感じのビットを生成するループ
        if (i >> k) & 1:
            Bit_i[k]*=-1
    for j in range(2**W): # 全てのビットを生成するループ
        Bit_j = list(range(1,W+1)) # [1,1,1...]の形でビットを初期化したリスト
        for l in range(W): #　いい感じのビットを生成するループ
            if (j >> l) & 1:
                Bit_j[l]*=-1
        count=0
        for a in Bit_i:
            for b in Bit_j:
                if a>0:
                    count+=(C[a-1][abs(b)-1]=='#')
                elif b>0:
                    count+=(C[abs(a)-1][b-1]=='#')
        ans+=(S-count==K)         

print(ans)

Submission status: Accepted

Solution code:
import copy
h,w,k=map(int,input().split())
v=[]
for _ in range(h):
    array=list(input())
    v.append(array)
ans=0
for a in range(2**h):
    c=copy.deepcopy(v)
    for b in range(h):
        if a>>b & 1:
            for d in range(w):
                c[b][d]=0
    for e in range(2**w):
      z=copy.deepcopy(c)
      temp=0
      for f in range(w):
        if e>>f & 1:
          for g in range(h):
            z[g][f]=0
      for p in range(h):
        temp+=z[p].count("#")
      if temp==k:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np


H, W, K = map(int,input().split())
L = np.zeros([6,6],dtype=int)
count = 0

# print(L)
for i in range(H):
    s = input()
    for j in range(W):
        if s[j-1] == "#":
            L[i,j] = 1

# print(L)

for i in range(2**H):
    for j in range(2**W):
        tmp = L.copy()
        for ib in range(H):
            if (i >> ib) & 1:
                tmp[ib,:] = 0
            for jb in range(W):
                if (j >> jb) & 1:
                    tmp[:,jb] = 0
        if np.sum(tmp) == K:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np

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

c = []

for _ in range(h):
    s = input()
    yoko = [0 if i=='.' else 1 for i in s]
    c.append(yoko)

c = np.array(c)

ans = 0

# for i in range(h):
#     arr = np.copy(c)
#     arr[i,:] = 0 
#     if arr.sum() == k:
#         ans += 1
#         print(arr)

# for j in range(w):
#     arr = np.copy(c)
#     arr[:,j] = 0
#     if arr.sum() == k:
#         ans += 1
#         print(arr)

# ç¸¦
for i in range(2**h):
    arr = np.copy(c)
 
    s = str(bin(i))
    condition = s[2:].zfill(h)

    for i_h in range(h):
        if condition[i_h] == '0':
            arr[i_h] = 0

    # æ¨ª
    for j in range(2**w):
        arr2 = np.copy(arr)

        s = str(bin(j))
        condition = s[2:].zfill(w)

        for j_w in range(w):
                
            if condition[j_w] == '0':
                arr2[:,j_w] = 0

        if arr2.sum() == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from math import *
from cmath import rect

def dft(f,x):
  if len(f)==1:
    return
  f0,f1=f[0::2],f[1::2]
  dft(f0,x)
  dft(f1,x)
  z=rect(1,x*2*acos(-1)/len(f))
  n=1+0j
  for i in range(len(f)):
    f[i]=f0[i%len(f0)]+n*f1[i%len(f1)]
    n=n*z

def pm(p,q):
  siz=1
  while len(p)+len(q)>siz:
    siz*=2
  np=[]
  nq=[]
  for i in range(len(p)):
    np.append(rect(p[i],0))
  for i in range(len(q)):
    nq.append(rect(q[i],0))
  while len(np)<siz:
    np.append(0+0j)
  while len(nq)<siz:
    nq.append(0+0j)
  dft(np,1)
  dft(nq,1)
  for i in range(siz):
    np[i]=np[i]*nq[i]
  dft(np,-1)
  EPS=0.1
  for i in range(siz):
    np[i]=int(np[i].real/siz+EPS)
  return np

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

def poly(x):
  r=[0]*x
  r.append(1)
  r[0]+=1
  return r

def knapsack(L):
  if len(L)==1:
    return poly(L[0])
  a=knapsack(L[:len(L)//2])
  b=knapsack(L[len(L)//2:])
  return pm(a,b)[:K+1]

for i in range(1,1<<H):
  X=[0]*W
  for j in range(H):
    if i&(1<<j):
      for k in range(W):
        if C[j][k]=='#':
          X[k]+=1
  DP=knapsack(X)
  if len(DP)>K:
    P+=DP[K]
print(P)

Submission status: Accepted

Solution code:
import numpy as np
H, W, K = map(int, input().split())
state = np.zeros((H, W), dtype=int)
for h in range(H):
  hlist = input()
  for w in range(W):
    if hlist[w] == "#":
      state[h][w]=1

startb = np.sum(state)
count = 0

if startb < K:
  print(0)
else:
  h_l = 2**H
  w_l = 2**W
  for h in range(h_l):
    for w in range(w_l):
      t1 = [int(i) for i in list(str(bin(h))[2:])]
      t2 = np.zeros(H-len(t1), dtype=int)
      wflag = np.append(t2, t1)
      state_t = state * np.array([wflag]*W).T

      t1 = [int(i) for i in list(str(bin(w))[2:])]
      t2 = np.zeros(W-len(t1), dtype=int)
      hflag = np.append(t2, t1)
      state_t = state_t * np.array([hflag]*H)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
"""
H, W, K = LI()
c = [[0 for j in range(W)] for i in range(H)]

for h in range(H):
    c[h] = list(str(input()))

# print(c)
for h in range(H):
    for w in range(W):
        if c[h][w] == ".":
            c[h][w] = 0
        else:
            c[h][w] = 1 


"""
# 2 ** (H + W)通り試せば良い
"""
ans = 0
# 10進数のnを2進数のリストに変換


def n2kdigit(n,k):
    digits = [0 for i in range(H + W)]
    tmp = 0
    while n > 0:
        digits[tmp] = n % k
        n = n // k
        tmp += 1

    return digits

for i in range(2 ** (H + W)):
    cnt = 0
    c_ = copy.deepcopy(c)
    digits = n2kdigit(i, k = 2)
    for j, digit in enumerate(digits):
        if digit == 1:
            if j >= H:
                for h in range(H):
                    # print(j - H -1)
                    c_[h][j - H - 1] = 0
            else:
                "Hを示す"
                c_[j] = [0 for k in range(W)]
    # print(c_)
    for h in range(H):
        cnt += sum(c_[h])
    if cnt == K:
        ans += 1

print(ans)


"""

# 実装例
H, W, K = list(map(int, input().split()))

c = []
for h in range(H):
    l = []
    for s in input():
        if s == ".":
            l.append(0)
        else:
            l.append(1)
    c.append(l)

ans = 0
for bit_h in range(2 ** H): # bit_hが2進数で隠すか隠さないかを示す
    for bit_w in range(2 ** W):
        k = 0
        nn = np.asarray(c)
        # mask 部分
        for h in range(H):
            """
            (bit_h & 2 ** h)の部分で，マスクがかかっている部分を調べる
            >> hによって，参照したい行が0 or 1なのかを調べる．0なら色がないので，したの作業がいらない
            """
            if (bit_h & 2 ** h) >> h == 0:
                continue
            nn[h] = np.zeros((1, W))
        for w in range(W):
            if (bit_w & 2 ** w) >> w == 0:
                continue
            nn[:, w] = np.zeros((1, H))
        # cnt部分
        if K == np.sum(nn):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
H,W,K=map(int,input().split())
C=[input() for i in range(H)]
DP=[0]*(K+1)
X=[]
P=0
for i in range(1,1<<H):
  X=[0]*W
  for j in range(H):
    if i&(1<<j):
      for k in range(W):
        if C[j][k]=='#':
          X[k]+=1
  for j in range(K+1):
    DP[j]=0
  DP[0]=1
  for j in range(W):
    for k in range(K,-1,-1):
      if k+X[j]<=K:
        DP[k+X[j]]+=DP[k]
  P+=DP[K]
print(P)

Submission status: Accepted

Solution code:
import copy
H, W, K = map(int,input().split())
C = [list(input()) for y in range(H)]
D = copy.deepcopy(C)       #Cの保管
ans = 0
import itertools


def retu(x):            #x+1列目を赤くする
    for y in range(H):
        C[y][x] = "R"

def gyou(x):            #x+1行目を赤くする
    for y in range(W):
        C[x][y] = "R"


for p in range(2**H):
    for q in range(2**W):
        for r in range(H):
            if p >> r & 1:
                gyou(r)
        for s in range(W):
            if q >> s & 1:
                retu(s)
        E = list(itertools.chain.from_iterable(C))  
        #１次元化して#の個数をわかりやすくする
        if E.count("#") == K:
            ans += 1
        C = copy.deepcopy(D)


print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
C = []
for _ in range(h): C.append(input())
from itertools import *
ans = 0
for bit in range(1<<(h+w)):
    c = 0
    for i, j in product(range(w, h+w), range(w)):
        if bit>>i & 1 and bit>>j & 1: c += C[i-w][j] == '#'
    if c == k: ans += 1
print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
C = []
for _ in range(h): C.append(input())
import itertools
ans = 0
for bit in range(1<<(h+w)):
    c = 0
    for i, j in itertools.product(range(w,h+w), range(w)):
        if bit>>i & 1 and bit>>j & 1: c += C[i-w][j] == '#'
    if c == k: ans += 1
print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
C = []
for _ in range(h): C.append(input())
import itertools
ans = 0
for bit in range(1<<(h+w)):
    c = 0
    for i in range(w, h+w):
        for j in range(w):
            if bit>>i & 1 and bit>>j & 1: c += C[i-w][j] == '#'
    if c == k: ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
for h_combo in range(2**H):
    for w_combo in range(2**W):
        curr_cnt = 0

        for i in range(H):
            for j in range(W):
                if (h_combo >> i) & 1 == 0 and (w_combo >> j) & 1 == 0:
                    if arr[i][j] == '#':
                        curr_cnt += 1
        
        if curr_cnt == K:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
h, w, k = map(int, input().split())
C = []
for _ in range(h): C.append(input())
import itertools
ans = 0
for bit in range(1<<(h+w)):
    c = 0
    for i in range(h):
        for j in range(w):
            if bit>>(w+i) & 1 and bit>>j & 1: c += C[i][j] == '#'
    if c == k: ans += 1
print(ans)

Submission status: Accepted

Solution code:
H, W, K= map(int, input().split())
c = [input() for i in range(H)]
true_cnt = 0
for j in range(2**H):
  bin_j = str(bin(j))[2:].zfill(H)
  for k in range(2**W):
    bin_k = str(bin(k))[2:].zfill(W)
    cnt = 0
    ##ここまでで切る列は決定 この後で解析
    for l in range(H):
      if bin_j[l] == "0":
        continue
      for m in range(W):
        if bin_k[m] == "0":
          continue
        elif c[l][m] == "#":
          cnt += 1
    if cnt == K:
      true_cnt += 1
print(true_cnt)

Submission status: Accepted

Solution code:
H, W, K = map(int, input().split())
arr = []
tot_cnt = 0
for _ in range(H):
    curr = list(input())
    arr.append(curr)
    tot_cnt += curr.count('#')

tot_moves = 0
for h_combo in range(2**H):
    h_combo = list(bin(h_combo)[2:])
    h_combo = ['0'] * (H - len(h_combo)) + h_combo
    
    for w_combo in range(2**W):
        w_combo = list(bin(w_combo)[2:])
        w_combo = ['0'] * (W - len(w_combo)) + w_combo

        curr_cnt = 0
        for i in range(H):
            if h_combo[i] == '1':
                curr_cnt += arr[i].count('#')
        
        for i in range(W):
            if w_combo[i] == '1':
                for j in range(H):
                    if h_combo[j] != '1':
                        curr_cnt += 1 if arr[j][i] == '#' else 0
        
        if tot_cnt - curr_cnt == K:
            tot_moves += 1

print(tot_moves)

Submission status: Accepted

Solution code:
import itertools
H,W,K = map(int, input().split())
#print(H,W,K)
ln = []
for i in range(H):
    sam = []
    sam2 = input()
    for j in sam2:
      sam.append(j)
    ln.append(sam)
#print(ln)
line_H = list(itertools.product([0,1],repeat = H))
line_W = list(itertools.product([0,1],repeat = W))
counter = 0
total = 0
for h in line_H:
    for w in line_W:
        
        counter = 0
        for i,k in enumerate(h):
            for j,l in enumerate(w):
                
                if ln[i][j] == '#' and k == 1 and l == 1:
                    counter +=1
                
        if counter == K:
            total += 1
print(total)

Submission status: Accepted

Solution code:
h,w,k = map(int,input().split())
a = []
for i in range(h):
	temp = []
	t = input()
	for j in range(w):
		if t[j] == ".": temp.append(0)
		else: temp.append(1)
	a.append(temp)
#print(a)
h_max = pow(2,h)
w_max = pow(2,w)
ans = 0
for i in range(h_max):
	h_str = str(bin(i)[2:])
	if len(h_str) < h: h_str = "0"*(h-len(h_str)) + h_str
	for j in range(w_max):
		w_str = str(bin(j)[2:])
		if len(w_str) < w: w_str = "0"*(w-len(w_str)) + w_str
		s = 0
		for m in range(h):
			for n in range(w):
				if h_str[m] == "0" and w_str[n] == "0":
					if a[m][n]: s += 1
		if s == k: ans += 1
		#print(h_str,w_str,s)
print(ans)

Submission status: Accepted

Solution code:
def INT():
    return int(input())

def MI():
    return map(int, input().split())

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

H, W, K = MI()
C = []

for _ in range(H):
    C.append(input())

ans = 0    

for h in range(1 << H):
    for w in range(1 << W):
        sharp = 0
        for i in range(H):
            if (h >> i) & 1:
                continue
            for j in range(W):
                if (w >> j) & 1:
                    continue
                sharp += int(C[i][j] == "#")
        
        if sharp == K:
            ans += 1

print(ans)

Submission status: Accepted

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


res = 0
for ih in range(1<<h):
    for iw in range(1<<w):

        h_use = [False] * h # 1: use
        w_use = [False] * w # 1: use
        for jh in range(h):
            if(ih & (1 << jh) != 0): h_use[jh] = True
        
        for jw in range(w):
            if(iw & (1 << jw) != 0): w_use[jw] = True

        cnt = 0
        for i in range(h):
            for j in range(w):
                
                if(h_use[i] or w_use[j]): continue
                if(c[i][j] == '.'): continue
                
                cnt += 1
        
        if(cnt == k): res += 1

print(res)

Submission status: Accepted

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

ans = 0
for n in range(1 << h):
    for m in range(1 << w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if n>>i & 1: continue
                if m>>j & 1: continue
                if c[i][j] == '#': cnt += 1
        if cnt == 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)]

res = 0
for use_h in product([0, 1], repeat=h):
    for use_w in product([0, 1], repeat=w):
        
        cnt = 0
        for i in range(h):
            for j in range(w):
                # if(use_h[i] == 1 or use_w[j] == 1): continue
                # if(c[i][j] == '.'): continue

                if(use_h[i] == 0 and use_w[j] == 0 and c[i][j] == '#'): cnt += 1
        
        if(cnt == k): res += 1

print(res)

Submission status: Accepted

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

origin = [list(input()) for _ in range(H)]
ans = 0
for i in range(2**H):
    for j in range(2**W):
        cnt = 0
        for h_shift in range(H):
            for w_shift in range(W):
                if i >> h_shift & 1 == 1 or j >> w_shift & 1: #赤で塗られるマス
                    continue
                if origin[h_shift][w_shift] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
H,W,K = map(int,input().split())
ll = []
for h in range(H):
    l = []
    for s in input():
        if s == ".":
            l.append(0)
        else:
            l.append(1)
    ll.append(l)
cnt = 0
for bh in range(2 ** H):
    for bw in range(2 ** W):
        nn = np.asarray(ll)
        k = 0
        for h in range(H):
            if (bh & 2 ** h) >> h == 0:
                continue
            nn[h] = np.array([0] * W)
        for w in range(W):
            if (bw & 2 ** w) >> w == 0:
                continue
            nn[:,w] = np.array([0] * H)
        for h in range(H):
            for w in range(W):
                k += nn[h][w]
        if k == K:
            cnt += 1
print(cnt)

Submission status: Accepted

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

C = [list(input()) for _ in range(h)]

ans = 0

for i in range(2**h):
    for j in range(2**w):
        count = 0
        for m in range(h):
            for n in range(w):
                if (i >> m) & 1 == 0 and (j >> n) & 1 == 0 and C[m][n] == '#':
                    count += 1
                else:
                    continue
        if count == k:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    H, W, K = map(int, readline().split())
    grid = []
    for _ in range(H):
        grid.append(list(readline().rstrip().decode()))
    #gridの状態をシミュレーションしない
    ans = 0
    for i in range(1<<H):
        for j in range(1<<W):
            cnt = 0
            for k in range(H):
                if (i>>k) & 1:
                    continue
                for l in range(W):
                    if (j>>l) & 1:
                        continue
                    if grid[k][l] == '#':
                        cnt += 1
            if cnt == K:
                ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

ans = 0
def main():
    H, W, K = map(int, readline().split())
    grid = []
    for _ in range(H):
        grid.append(list(input()))

    #再帰関数で二組の全bit探索を組む 
    #リストをコピーしない方法
    bitr = [0 for _ in range(H)]
    bitc = [0 for _ in range(W)]
    
    def dfsr(i): 
        if i == H:
            dfsc(0)
            return
        dfsr(i+1)
        bitr[i] = 1
        dfsr(i+1)        
        bitr[i] = 0
    
    def dfsc(i):
        global ans
        cnt = 0
        if i == W:
            #ここで処理をおこなう
            for j in range(H):
                #1が立っているならその行は全て赤とするので飛ばす
                if bitr[j] == 1: 
                    continue
                for k in range(W):
                    #1が立っているならその列は全て赤とするので飛ばす
                    if bitc[k] == 1:
                        continue
                    #飛ばされなかったマスのうち黒の数を数える
                    if grid[j][k] == '#':
                        cnt += 1
            if cnt == K:
                ans += 1
            return
        dfsc(i+1) 
        bitc[i] = 1
        dfsc(i+1)
        bitc[i] = 0
    
    dfsr(0)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import copy
deta = [0,1]

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

c = [list(input()) for _ in range(h)]

#print(c)

h1 = list(itertools.product(deta, repeat=h))
w1 = list(itertools.product(deta, repeat=w))

count = 0

for i in h1:
    for j in w1:
        c1 = copy.deepcopy(c)
        for k in range(h):
            if i[k] == 1:
                for l in range(w):
                    c1[k][l] = '.'
        for l in range(w):
            if j[l] == 1:
                for k in range(h):
                    c1[k][l] = '.'
        #print(c1)

        temp = 0
        for k in range(h):
            for l in range(w):
                if c1[k][l] == "#":
                    temp += 1
        if temp == k1:
            count += 1

print(count)

Submission status: Accepted

Solution code:
h, w, x = map(int, input().split())
matrix = []
total = 0
row = []
col = [0] * w
for _ in range(h):
  c = input()
  cnt = 0
  for i in range(w):
    if c[i] == '#':
      cnt += 1
      col[i] += 1
  total += cnt
  row.append(cnt)
  matrix.append(c)

ans = 0
for k in range(2**h):
  for l in range(2**w):
    state = total
    r_lst = []
    c_lst = []
    for i in range(h):
      if k & (1 << i) == 2**i:
        state -= row[i]
        r_lst.append(i)
    for j in range(w):
      if l & (1 << j) == 2**j:
        state -= col[j]
        c_lst.append(j)
    for p in r_lst:
      for q in c_lst:
        if matrix[p][q] == '#':
          state += 1
    if state == x:
      ans += 1
print(ans)