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! my_write {
  ($writer:expr, $arg:expr)            => { $writer.write($arg).unwrap() };
  ($writer:expr, $arg:expr,)           => { my_write!($writer, $arg) };
  ($writer:expr, $($arg:expr),+ $(,)?) => { $($writer.write($arg).unwrap();)+ };
}

use std::io::{
  stdin,
  stdout,
  Write,
  BufRead,
  BufReader,
  BufWriter
};

use std::ops::{
  Not,
  BitAnd,
  BitXor
};

use num_traits::{
  identities::{
    Zero,
    One
  },
  ops::wrapping::WrappingAdd
};

fn fold_bitflag<T, U, F>(mut n: T, mut init: U, mut func: F) -> U
  where F: FnMut(U, T) -> U,
        T: Copy +
           PartialEq +
           Not<Output=T> +
           BitAnd<Output=T> +
           BitXor<Output=T> +
           Zero +
           One +
           WrappingAdd
{
  loop {
    let flg = n & (!n).wrapping_add(&T::one());
    if flg == T::zero() {
      break init;
    }
    init = func(init, flg);
    n = n ^ flg;
  }
}

fn abc173_c<R, W>(
  mut scanner: my::Scanner<R>,
  mut writer : BufWriter<W>,
  #[allow(unused_variables, unused_mut)]
  mut itoa   : my::ItoA
)
  where R: BufRead,
        W: Write
{
  let h = my::atoi::<usize>(scanner.read_until(my::SP));
  let w = my::atoi::<usize>(scanner.read_until(my::SP));
  let k = my::atoi::<u32>(scanner.read_until(my::LF));

  let vec = scanner.fold(h, my::LF, Vec::with_capacity(h), | mut acc, s | {
    let mut n: u8 = 0;
    for i in 0..w {
      n |= if s[i] == b'.' { 0 } else { 1 << i }
    }
    acc.push(n);
    acc
  });

  let mut ans = 0;

  for row in 0..1 << h {
    for col in 0..1 << w {
      let cnt = fold_bitflag(row, 0, | acc, x: u8 | {
        let i = x.trailing_zeros() as usize;
        acc + (vec[i] & col).count_ones()
      });

      if cnt == k {
        ans += 1;
      }
    }
  }

  my_write!(writer, itoa.from(ans), b"\n");
  writer.flush().unwrap();
}

fn main() {
  let stdin  = stdin();
  let stdout = stdout();

  abc173_c(
    my::Scanner::with_capacity(12, BufReader::new(stdin.lock())),
    BufWriter::new(stdout.lock()),
    my::ItoA::with_capacity(10));
}

//------------------------------------------------------------------------
mod my {
  use std::ops::{
    Add,
    Sub,
    Mul,
    Div,
    Rem,
    Not
  };

  use num_traits::{
    cast::NumCast,
    ops::wrapping::WrappingAdd,
    identities::{
      Zero,
      One
    }
  };

  #[allow(dead_code)]
  pub const SP: u8 = b' ';
  #[allow(dead_code)]
  pub const LF: u8 = b'\n';

  macro_rules! num_cast {
    ($v0:expr)          => { num_traits::cast::cast::<_, _>($v0).unwrap() };
    ($v0:expr, $ret:ty) => { num_traits::cast::cast::<_, $ret>($v0).unwrap() };
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  fn atoi0<T, F>(s: &[u8], mut n: T, func: F) -> T
    where F: Fn(T, T) -> T,
          T: Mul<Output=T> +
             NumCast
  {
    for b in s {
      n = func(n * num_cast!(10), num_cast!(b - b'0'));
    }
    n
  }

  #[allow(dead_code)]
  pub fn atoi<T>(s: &[u8]) -> T
    where T: Add<Output=T> +
             Sub<Output=T> +
             Mul<Output=T> +
             NumCast +
             Zero
  {
    let n = T::zero();

    if s.is_empty() {
      return n;
    }

    match s[0] {
      b'+' => atoi0(&s[1..], n, T::add),
      b'-' => atoi0(&s[1..], n, T::sub),
      _    => atoi0(&s[0..], n, T::add),
    }
  }

  //----------------------------------------------------------------------
  pub struct ItoA {
    buf: Vec<u8>,
  }

  impl ItoA {
    #[allow(dead_code)]
    pub fn with_capacity(capa: usize) -> Self {
      Self {
        buf: Vec::with_capacity(capa),
      }
    }

    #[allow(dead_code)]
    pub fn from<T>(&mut self, mut n: T) -> &[u8]
      where T: Copy +
               PartialEq +
               PartialOrd +
               Div<Output=T> +
               Rem<Output=T> +
               Not<Output=T> +
               NumCast +
               Zero +
               One +
               WrappingAdd
    {
      let zero = T::zero();
      let one  = T::one();
      let ten  = num_cast!(10);

      self.buf.clear();
      if n == zero {
        self.buf.push(b'0');
        return self.buf.as_slice();
      }

      let mut is_negative = false;
      if n < zero {
        is_negative = true;
        n = (!n).wrapping_add(&one);
      }

      while n > zero {
        self.buf.push(num_cast!(n % ten, u8) + b'0');
        n = n / ten;
      }
      if is_negative {
        self.buf.push(b'-');
      }
      self.buf.reverse();
      self.buf.as_slice()
    }
  } // impl ItoA

  //----------------------------------------------------------------------
  pub struct Scanner<R> {
    reader: R,
    buf   : Vec<u8>,
  }

  impl<R> Scanner<R>
    where R: ::std::io::BufRead
  {
    #[allow(dead_code)]
    pub fn with_capacity(capa: usize, reader: R) -> Self {
      Self {
        reader: reader,
        buf   : Vec::with_capacity(capa),
      }
    }

    #[allow(dead_code)]
    pub fn read_until(&mut self, delim: u8) -> &[u8] {
      self.buf.clear();
      let mut len = self.reader.read_until(delim, &mut self.buf).unwrap();
      if len == 0 {
        return self.buf.as_slice();
      }

      len -= 1;
      if self.buf[len] == delim {
        self.buf.truncate(len);
      }
      self.buf.as_slice()
    }

    #[allow(dead_code)]
    pub fn for_each<F>(&mut self, n: usize, delim: u8, mut func: F)
      where F: FnMut(&[u8])
    {
      for _ in 0..n - 1 {
        func(self.read_until(delim));
      }
      func(self.read_until(LF))
    }

    #[allow(dead_code)]
    pub fn fold<T, F>(&mut self, n: usize, delim: u8, mut init: T, mut func: F) -> T
      where F: FnMut(T, &[u8]) -> T
    {
      for _ in 0..n - 1 {
        init = func(init, self.read_until(delim));
      }
      func(init, self.read_until(LF))
    }
  } // impl<R> Scanner<R>
} // mod my