1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int n;
vector<vector<bool>> used;

struct Point {
    int x, y;

    Point(int xx, int yy) : x(xx), y(yy) {}

    vector<Point> neigh() {
        vector<Point> p;

        for(int dx: {-1, 0, 1}) {
            for(int dy: {-1, 0, 1}) {
                if (abs(dx)+abs(dy) != 1)
                    continue;

                auto xx = x + dx;
                auto yy = y + dy;

                if (0 <= xx && xx < n && 0 <= yy && yy < n && !used[yy][xx]) {
                    p.emplace_back(xx, yy);
                }
            }
        }

        return  p;
    }
};

bool operator<(const Point& lhs, const Point& rhs) {
    return make_pair(lhs.x, lhs.y) < make_pair(rhs.x, rhs.y);
}
bool operator==(const Point& lhs, const Point& rhs) {
    return make_pair(lhs.x, lhs.y) == make_pair(rhs.x, rhs.y);
}
std::ostream& operator<<(std::ostream& stream, const Point& p) {
    stream << "(" << p.x << ", " << p.y << ")";
    return stream;
}
std::ostream& operator<<(std::ostream& stream, const vector<Point>& p) {
    stream << "[";
    for(auto x : p) {
        stream << x << " ";
    }
    stream << "]";
    return stream;
}
std::ostream& operator<<(std::ostream& stream, const set<Point>& p) {
    stream << "[";
    for(auto x : p) {
        stream << x << " ";
    }
    stream << "]";
    return stream;
}






vector<Point> line1;
set<set<Point>> solutions;

int k;

void gen(vector<Point> now) {
//    cout << "Generate " << now << endl;

    if (now.size() == k) {
//        cout << "Solution!" << endl;
        set<Point> now_sol;
        for(auto x : now) {
            now_sol.insert(x);
        }
        solutions.insert(now_sol);
        return;
    }

    for(auto x : line1) {
//        cout << "try" << x << endl;
        if (std::find(now.begin(), now.end(), x) == now.end()) {
            now.push_back(x);
            gen(now);
            now.pop_back();
        }
    }

    if (now.size() == 0) {
        return;
    }
    for(auto x : now.rbegin()->neigh()) {
//        cout << "Now: " << x << std::endl;
        if (std::find(now.begin(), now.end(), x) == now.end()) {
            now.push_back(x);
            gen(now);
            now.pop_back();
        }
    }
}

int main() {
    scanf("%d%d", &n, &k);

    used.resize(n);
    for(auto& x: used) {
        x.resize(n);
    }

    for(int y = n-1; y >= 0; --y) {
        char line[3100];
        scanf("%s", line);

        for(int x = 0; x < n; ++x) {
            if (line[x] == '#') {
                used[y][x] = true;
            } else {
                used[y][x] = false;
            }

        }
    }

    for(int y = 0; y < n; ++y) {
        for(int x = 0; x < n; ++x) {
            if (used[y][x]) {
                auto now = Point(x, y);
//                cout << now << ":";

                for(auto x: now.neigh()) {
//                    cout << x << ",";
                    line1.push_back(x);
                }
//                cout << endl;
            }

        }
    }

    gen({});

//    cout << endl << endl;
//
//    for(auto x : solutions) {
//        cout << x << endl;
//    }

    cout << solutions.size() << endl;



    return 0;
}