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)

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn convert_to_bitstring(n: u32, keta: usize) -> Vec<usize> {
    let mut svec: Vec<u32> = Vec::new();
    let mut val = n;
    let base: u32 = 2;
    for i in (0..keta).rev() {
        svec.push(val / base.pow(i as u32));
        // println!("{}, {}, {}", val, base.pow(i), val / base.pow(i));
        val = val % base.pow(i as u32);
    }
    let mut vals: Vec<usize> = Vec::new();
    for (i, val) in svec.into_iter().rev().enumerate() {
        if val == 1 {
            vals.push(i);
        }
    }
    vals
}

fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
        board: [chars; h],
    };

    // それぞれの行・列でどれだけ黒いますがあるのか計算しておく
    let mut blacks_h: Vec<usize> = Vec::new(); // 行ごとの黒の数
    for i in 0..h {
        let mut black = 0;
        let cc = board.get(i).expect("");
        for c in cc {
            if c == &'#' {
                black += 1;
            }
        }
        blacks_h.push(black);
    }
    // println!("blacks_h: {:?}", blacks_h);
    let mut blacks_w: Vec<usize> = Vec::new(); // 列ごとの黒の数
    for i in 0..w {
        let mut black = 0;
        for gyou in board.clone() {
            if gyou.get(i).unwrap() == &'#' {
                black += 1;
            }
        }
        blacks_w.push(black);
    }
    // println!("blacks_w: {:?}", blacks_w);

    let mut black_sum = 0; // 全体での黒の数
    for val in blacks_w.clone() {
        black_sum += val;
    }
    // println!("black_sum: {:?}", black_sum);

    // どの行・列を赤く塗るか全通りを考える
    let mut ans = 0;
    let base: u32 = 2;
    for i in 0..(base.pow(w as u32)) {
        let base: u32 = 2;
        for j in 0..(base.pow(h as u32)) {
            // 今回赤く塗る行・列
            let w_bitset = convert_to_bitstring(i, w);
            let h_bitset = convert_to_bitstring(j, h);
            let mut black_w = 0;
            let mut black_h = 0;
            let mut black_wh = 0;

            for i in w_bitset.clone() {
                black_w += blacks_w.get(i).expect("");
            }
            for j in h_bitset.clone() {
                black_h += blacks_h.get(j).expect("");
            }
            for i in w_bitset.clone() {
                for j in h_bitset.clone() {
                    if board[j][i] == '#' {
                        black_wh += 1;
                    }
                }
            }
            let black = black_sum + black_wh - black_w - black_h;
            if black == k {
                ans += 1;
            }
            /*
            println!(
                "w: {:?}, h: {:?}, black_w: {}, black_h: {}, black_wh: {} => {}",
                w_bitset, h_bitset, black_w, black_h, black_wh, black
            );
            */
        }
    }
    println!("{}", ans);
}