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
| #include <cstdio> #include <iostream>
using namespace std;
int n,k; int cnt; char c[10][10]; bool vis[10][10]; bool cc[10];
void dfs(int x,int way){ if(way == k){ cnt++; return ; } if(x > n) return ; for(int i = 1; i <= n ; i++){ if(c[x][i] == '#' && cc[i] == 0){ cc[i] = 1; dfs(x+1,way+1); cc[i] = 0; } } dfs(x+1,way); }
int main(){ char chr; while(scanf("%d %d",&n,&k)!=EOF){ if(n == -1 && k == -1){ break; } cnt = 0; getchar(); for(int i = 1 ; i <= n ; i++){ for(int j = 1 ; j <= n ; j++){ scanf("%c",&chr); c[i][j] = chr; if(chr == '#'){ vis[i][j] = 1; } else{ vis[i][j] = 0; } } getchar(); } dfs(0,0); printf("%d\n",cnt); } return 0; }
|
Author:
Qin Peng
License:
Copyright (c) 2020 BY QPWLKQ LICENSE
Slogan:
每一个不曾起舞的日子, 都是对生命的辜负