题目大意:
n
皇后。
分析:
AC code:
#include <cstdio>
#include <iostream>
#define ONLINE_JUDGE
const int MAXN = 19;
int n, k;
int d1[MAXN<<1];
int d2[MAXN<<1];
int c[MAXN];
int dfs(int now, int tk)
{
if(tk == k) return 1;
if(now == n+1) return 0;
int ret = dfs(now+1, tk);
for(int i = 1; i <= n; ++i)
if(!d1[now+i] && !d2[now-i+n] && !c[i])
{
d1[now+i] = d2[now-i+n] = c[i] = 1;
ret += dfs(now+1, tk+1);
d1[now+i] = d2[now-i+n] = c[i] = 0;
}
return ret;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("sgu224.in", "r", stdin);
freopen("sgu224.out", "w", stdout);
#endif
std::ios::sync_with_stdio(0);
std::cin >> n >> k;
std::cout << dfs(1, 0) << std::endl;
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}