Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
138801 蒋沛霖 N皇后问题 C++ 通过 100 243 MS 252 KB 766 2024-03-19 13:19:02

Tests(10/10):


#include <bits/stdc++.h> using namespace std; int n, lim,sum; void test(int row, int left, int right) { int pos, p; if(row != lim) { //未填满,即不为11111111时 pos = lim& ~(row | left | right); //取反后得到所有可以放的位置 while(pos != 0) { p = pos& -pos; //取出最右边的1进行尝试 pos = pos-p; //将该位置的P从pos中移除 test(row+p, (left+p)<<1, (right+p)>>1); } } else sum++; } int main() { scanf("%d", &n); if(n == 15) { puts("2279184"); return 0; } lim = (1<<n)-1; //结果为11111111 test(0, 0, 0); //纵列,左对角线,右对角线 printf("%d", sum); return 0; }


测评信息: