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

Solution in C (GCC 9.2.1) (judge verdict: Accepted)

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ON			1										// 汎用フラグ - ON
#define D_OFF			0										// 汎用フラグ - OFF
#define D_SIZE_MAX		10										// 最大サイズ

// 内部変数
static FILE *szpFpI;											// 入力
static int siW, siH;											// 幅・高さ
static char sc2Mass[D_SIZE_MAX][D_SIZE_MAX];					// マス
static int siBCnt;												// 黒数
static int siPCnt;												// パターン数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 選択
int
fSel(
	int piRow					// <I> 行
	, int piCol					// <I> 列
	, char *pcpRow				// <I> 選択行
	, char *pcpCol				// <I> 選択列
)
{
	int i, j;

	// 行選択
	if (piRow < siH) {

		// あり
		pcpRow[piRow] = D_ON;
		fSel(piRow + 1, piCol, pcpRow, pcpCol);

		// なし
		pcpRow[piRow] = D_OFF;
		fSel(piRow + 1, piCol, pcpRow, pcpCol);
	}

	// 列選択
	else if (piCol < siW) {

		// あり
		pcpCol[piCol] = D_ON;
		fSel(piRow, piCol + 1, pcpRow, pcpCol);

		// なし
		pcpCol[piCol] = D_OFF;
		fSel(piRow, piCol + 1, pcpRow, pcpCol);
	}

	// 選択終了
	else {

		// マス - セット
		char lc2Mass[D_SIZE_MAX][D_SIZE_MAX];
		memcpy(lc2Mass, sc2Mass, sizeof(lc2Mass));
		for (i = 0; i < siH; i++) {
			if (pcpRow[i] == D_ON) {
				for (j = 0; j < siW; j++) {
					lc2Mass[i][j] = 0;
				}
			}
		}
		for (i = 0; i < siW; i++) {
			if (pcpCol[i] == D_ON) {
				for (j = 0; j < siH; j++) {
					lc2Mass[j][i] = 0;
				}
			}
		}

		// 黒数 - 取得
		int liBCnt = 0;
		for (i = 0; i < siH; i++) {
			for (j = 0; j < siW; j++) {
				if (lc2Mass[i][j] == '#') {
					liBCnt++;
				}
			}
		}

		// パターン数 - 加算
		if (liBCnt == siBCnt) {
			siPCnt++;
		}
	}

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// データ - 初期化
	siPCnt = 0;

	// 幅・高さ・黒数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d%d", &siH, &siW, &siBCnt);

	// マス - 取得
	for (i = 0; i < siH; i++) {
		fgets(sc2Mass[i], sizeof(sc2Mass[0]), szpFpI);
	}

	// 選択
	char lc1Row[D_SIZE_MAX], lc1Col[D_SIZE_MAX];
	fSel(0, 0, lc1Row, lc1Col);

	return siPCnt;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}