#include #include using namespace std; void log_array(const vector& arr, const string& name) { clog << name << ": "; for (const auto& cell : arr) { clog << cell << " "; } clog << endl; } vector> get_grid(const int size) { vector> grid; for (int _ = 0; _ < size; _++) { string pattern; vector row; cin >> pattern; for (const char c : pattern) { row.push_back(c != '.'); } grid.push_back(row); } return grid; } long long dfs(const vector>& grid, const int remaining_chests, const int curr_empty_row, vector& col_occupation) { const unsigned int size = grid[0].size(); if (remaining_chests == 0) { return 1; } if (curr_empty_row >= size) { return 0; } // clog << "curr_empty_row: " << curr_empty_row << endl; // log_array(col_occupation, "col_occupation"); long long ans = 0; for (int col = 0; col < size; col++) { // 这行放 if (!grid[curr_empty_row][col]) { continue; } if (col_occupation[col]) { continue; } // vector new_col_occupation(col_occupation); col_occupation[col] = true; ans += dfs(grid, remaining_chests - 1, curr_empty_row + 1, col_occupation); col_occupation[col] = false; } ans += dfs(grid, remaining_chests, curr_empty_row + 1, col_occupation); // 不在这行放 return ans; } long long dfs(const vector>& grid, const int remaining_chests, const int curr_empty_row = 0) { vector col_occupation(grid[0].size(), false); return dfs(grid, remaining_chests, curr_empty_row, col_occupation); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int size, chest_count; while (cin >> size >> chest_count) { if (size < 0) { break; } vector> grid = get_grid(size); cout << dfs(grid, chest_count) << endl; } // cin >> size; // chest_count = size; // const vector> grid = get_grid(size); // cout << dfs(grid, chest_count) << endl; return 0; }