poj 1312

 

 

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,k;
char ch[10][10];
long long ans;
int vis[10];
int kk;
void dfs(int x){
    if(kk == k){
        ans++;
        return;
    }
    if(x >= n) return;
    for(int y = 0; y < n; y++){
        if(!vis[y] && ch[x][y] == '#'){
            vis[y] = 1;
            kk++;
            dfs(x + 1);
            vis[y] = 0;
            kk--;
        }
    }
    dfs(x + 1);
}
int main(){
   // freopen("in","r",stdin);
    ios::sync_with_stdio(0);
    while(cin >> n >> k){
        if(n == -1 && k == -1)
            break;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cin >> ch[i][j];
            }
        }
        memset(vis,0, sizeof(vis));
        ans = 0;
        kk = 0;
        dfs(0);
        cout << ans << endl;
    }
    return 0;
}

 

posted @ 2020-04-12 09:56  Hazelxcf  阅读(152)  评论(0)    收藏  举报