CodeVS 1295 N皇后问题 题解

来源:互联网 发布:c语言中的贪心算法 编辑:程序博客网 时间:2024/06/07 10:40
#include <cstdio>using namespace std;bool a[13+2], b[26+2], c[26+2];int N, num;void checker(int n){if(n>N){++num;return;}for(int i = 1; i<=N; ++i){        if(!a[i] && !b[i+n] && !c[i-n+12]){    a[i] = b[i+n] = c[i-n+12] = true;    checker(n+1);    a[i] = b[i+n] = c[i-n+12] = false;}}}int main(){    scanf("%d",&N);checker(1);printf("%d\n", num);return 0;}