标签:八皇后问题 code bitmap span bsp amp 为什么 count col
为什么是这么做的?
1 void backtracking(int row, int n, int left, int right, int col, int &count) 2 { 3 if (row == n) 4 { 5 count++; 6 } 7 int bits = (~(col | left | right))&((1 << n) - 1); 8 9 while (bits) 10 { 11 int bit = -bits & bits; 12 backtracking(row + 1, n, (left | bit) << 1, (right | bit) >> 1, col | bit, count); 13 bits = bits ^ bit; 14 } 15 } 16 int totalNQueens(int n) { 17 int count = 0; 18 backtracking(0,n,0,0,0,count); 19 return count; 20 }
标签:八皇后问题 code bitmap span bsp amp 为什么 count col
原文地址:https://www.cnblogs.com/zouma/p/11604330.html