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 Rust (1.42.0) (judge verdict: Accepted)

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// bin全探索でc問題を解く
fn main() {
    // 入力
    let line:String = read();
    let s: Vec<&str> = line.split(' ').collect();
    let h: i32 = s[0].parse().unwrap();
    let w: i32 = s[1].parse().unwrap();
    let k: i32 = s[2].parse().unwrap();
    //println!("{}, {}, {}", h, w, k);

    let mut v: Vec<String> = Vec::new();
    let mut v1: Vec<char> = Vec::new();
    let mut v2: Vec<Vec<char>> = Vec::new();
    let mut count: i32 = 0;
    for _ in 0..h {
        let s: String = read();
        v1 = s.chars().collect();
        v2.push(v1);
    }
    //println!("{}", pow(2, (h + w) - 1) - 1);
    for i in 0..pow(2, h + w - 1) - 1 {
        if calc_black(v2.clone(), i, h as usize, w as usize, k) {
            count += 1;
        }
    }

    // 処理
    // 入力Cに対して渡されたbit列から消す列を計算して黒の数を返す関数

    // 出力
    // countしたresultを出す
    println!("{}", count);
}

// blocksと消す行と列のbit列を計算して#がk個ならtrueを返す
fn calc_black(mut blocks: Vec<Vec<char>>, num:i32, h: usize, w:usize, k: i32) -> bool {
    let mut result_count: i32 = 0;
    // numの2進数化
    for i in 0..calc_keta(num, 2) {
        let index = calc_keta(num & 1 << i, 2);
        if index == 0 {
            continue;
        }
        if index > 0 && index <= h {
            for j in 0..w {
                blocks[index-1][j] = 'r';
            }
        } else {
            for j in 0..h {
                //println!("h={}, w={}, index = {}, num = {}",j, index - h, index, num);
                blocks[j][index - 1 - h] = 'r';
            }
        }
        /*
        match index {
            h_index @ 0..=h => {
                for i in 0..w {
                    blocks[h_index][i] = '#';
                }  
            },
            w_index @ h..=w => {
                for i in 0..h {
                    blocks[i][w_index] = '#';
                }
            },
            _ => (),
        }
        */
    }

    // カウントを取る
    for i in 0..h {
        for j in 0..w {
            if blocks[i][j] == '#' {
                result_count += 1;
            }
        }
    }
    return result_count == k;
}

// baseのp乗
fn pow(base: i32, p: i32) -> i32 {
    let mut result: i32 = base;
    for _i in 0..p {
        result *= base;
    }

    result
}
fn calc_keta(mut num: i32, kisu: i32) -> usize {
    let mut count = 0;
    if num == 0 {
        return 0;
    }
    while num / kisu != 0{
        count += 1;
        num /= kisu;
    }
    count += 1;
    return count;
}