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 <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define endl "\n"
#define int long long
#define debug(x) cout << #x << " is " << x << endl;
using namespace std;
int k;
int ok(vector <int> &boolw, vector <int>& boolh, vector <string> grid) {
    for (int i = 0; i < boolh.size(); ++i) {
        if (boolh[i]) {
            for (int j = 0; j < boolw.size(); ++j) grid[i][j] = '0';
        }
    }
    for (int i = 0; i < boolw.size(); ++i) {
        if (boolw[i]) {
            for (int j = 0; j < boolh.size(); ++j) grid[j][i] = '0';
        }
    }
    int ans = 0;
    for (int i = 0; i < boolh.size(); ++i) {
        for (int j = 0; j < boolw.size(); ++j) if (grid[i][j] == '#') ++ans;
    }
    if (ans == k) return 1;
    return 0;
}

int cou(int w, vector <int>& boolh, vector <string> grid) {
    int ans = 0;
    vector <int> boolw(w, 0);
    for (int i1 = 0; i1 < 2; ++i1) {
        boolw[0] = 1 - boolw[0];
        if (w == 1) ans += ok(boolw, boolh, grid);
        else for (int i2 = 0; i2 < 2; ++i2) {
            boolw[1] = 1 - boolw[1];
            if (w == 2) ans += ok(boolw, boolh, grid);
            else for (int i3 = 0; i3 < 2; ++i3) {
                boolw[2] = 1 - boolw[2];
                if (w == 3) ans += ok(boolw, boolh, grid);
                else for (int i4 = 0; i4 < 2; ++i4) {
                    boolw[3] = 1 - boolw[3];
                    if (w == 4) ans += ok(boolw, boolh, grid);
                    else for (int i5 = 0; i5 < 2; ++i5) {
                        boolw[4] = 1 - boolw[4];
                        if (w == 5) ans += ok(boolw, boolh, grid);
                        else for (int i6 = 0; i6 < 2; ++i6) {
                            boolw[5] = 1 - boolw[5];
                            if (w == 6) ans += ok(boolw, boolh, grid);
                        }
                    }
                }
            }
        }
    }
    return ans;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(2);
    int h, w, ans = 0; cin >> h >> w >> k;
    vector <string> grid(h);
    for (auto& x : grid) cin >> x;
    vector <int> boolh(h, 0), boolw(w, 0);
    for (int i1 = 0; i1 < 2; ++i1) {
        boolh[0] = 1 - boolh[0];
        if (h == 1) ans += cou(w, boolh, grid);
        else for (int i2 = 0; i2 < 2; ++i2) {
            boolh[1] = 1 - boolh[1];
            if (h == 2) ans += cou(w, boolh, grid);
            else for (int i3 = 0; i3 < 2; ++i3) {
                boolh[2] = 1 - boolh[2];
                if (h == 3) ans += cou(w, boolh, grid);
                else for (int i4 = 0; i4 < 2; ++i4) {
                    boolh[3] = 1 - boolh[3];
                    if (h == 4) ans += cou(w, boolh, grid);
                    else for (int i5 = 0; i5 < 2; ++i5) {
                        boolh[4] = 1 - boolh[4];
                        if (h == 5) ans += cou(w, boolh, grid);
                        else for (int i6 = 0; i6 < 2; ++i6) {
                            boolh[5] = 1 - boolh[5];
                            if (h == 6) ans += cou(w, boolh, grid);
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;


}