C - H and V Editorial /

Time Limit: 1 sec / Memory Limit: 1024 MB

配点 : 300300

問題文

HHWW 列に並ぶマスからなるマス目があります。上から ii 行目、左から jj 列目 (1iH,1jW)(1 \leq i \leq H, 1 \leq j \leq W) のマスの色は文字 ci,jc_{i,j} として与えられ、ci,jc_{i,j}. のとき白、# のとき黒です。

次の操作を行うことを考えます。

  • 行を何行か選び (00 行でもよい)、列を何列か選ぶ (00 列でもよい)。そして、選んだ行に含まれるマスと、選んだ列に含まれるマスをすべて赤く塗る。

正の整数 KK が与えられます。操作後に黒いマスがちょうど KK 個残るような行と列の選び方は何通りでしょうか。ここで、二つの選び方は、一方においてのみ選ばれる行または列が存在するときに異なるとみなされます。

制約

  • 1H,W61 \leq H, W \leq 6
  • 1KHW1 \leq K \leq HW
  • ci,jc_{i,j}. または #

入力

入力は以下の形式で標準入力から与えられる。

HH WW KK
c1,1c1,2...c1,Wc_{1,1}c_{1,2}...c_{1,W}
c2,1c2,2...c2,Wc_{2,1}c_{2,2}...c_{2,W}
::
cH,1cH,2...cH,Wc_{H,1}c_{H,2}...c_{H,W}

出力

条件を満たす行と列の選び方の個数を表す整数を出力せよ。


入力例 1Copy

Copy
2 3 2
..#
###

出力例 1Copy

Copy
5

以下の 55 通りの選び方が条件を満たします。

  • 11 行目、11 列目
  • 11 行目、22 列目
  • 11 行目、33 列目
  • 11 列目、22 列目
  • 33 列目

入力例 2Copy

Copy
2 3 4
..#
###

出力例 2Copy

Copy
1

何も選ばないという 11 通りの選び方が条件を満たします。


入力例 3Copy

Copy
2 2 3
##
##

出力例 3Copy

Copy
0

入力例 4Copy

Copy
6 6 8
..##..
.#..#.
#....#
######
#....#
#....#

出力例 4Copy

Copy
208

Score : 300300 points

Problem Statement

We have a grid of HH rows and WW columns of squares. The color of the square at the ii-th row from the top and the jj-th column from the left (1iH,1jW)(1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character ci,jc_{i,j}: the square is white if ci,jc_{i,j} is ., and black if ci,jc_{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 KK. How many choices of rows and columns result in exactly KK 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

  • 1H,W61 \leq H, W \leq 6
  • 1KHW1 \leq K \leq HW
  • ci,jc_{i,j} is . or #.

Input

Input is given from Standard Input in the following format:

HH WW KK
c1,1c1,2...c1,Wc_{1,1}c_{1,2}...c_{1,W}
c2,1c2,2...c2,Wc_{2,1}c_{2,2}...c_{2,W}
::
cH,1cH,2...cH,Wc_{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 1Copy

Copy
2 3 2
..#
###

Sample Output 1Copy

Copy
5

Five choices below satisfy the condition.

  • The 11-st row and 11-st column
  • The 11-st row and 22-nd column
  • The 11-st row and 33-rd column
  • The 11-st and 22-nd column
  • The 33-rd column

Sample Input 2Copy

Copy
2 3 4
..#
###

Sample Output 2Copy

Copy
1

One choice, which is choosing nothing, satisfies the condition.


Sample Input 3Copy

Copy
2 2 3
##
##

Sample Output 3Copy

Copy
0

Sample Input 4Copy

Copy
6 6 8
..##..
.#..#.
#....#
######
#....#
#....#

Sample Output 4Copy

Copy
208


2025-04-22 (Tue)
20:38:52 +00:00