POJ-1321 棋盘问题
作者:互联网
A - 棋盘问题 (POJ - 1321)
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 8;
char b[N][N] = {0};
bool vis[N] = {0};
int n, k, ans = 0;
void dfs(int x, int cnt) {
if(cnt>=k) {
ans++;
return ;
}
for(int i=x; i<n; i++) {
for(int j=0; j<n; j++) {
if(b[i][j]=='#' && !vis[j]) {
vis[j] = true;
dfs(i+1, cnt+1);
vis[j] = false;
}
}
}
}
int main(void) {
while(scanf("%d%d", &n, &k)==2 && n!=-1 && k!=-1) {
ans = 0;
memset(vis, 0, sizeof(vis));
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
scanf(" %c", &b[i][j]);
dfs(0, 0);
printf("%d\n", ans);
}
return 0;
}
标签:1321,const,int,long,POJ,ans,棋盘 来源: https://blog.csdn.net/IT1656409967/article/details/96963569