N-Queens II
2014-09-16 15:12
127 查看
class Solution { //always pay attention to do not change the parameters in current level by forwarding public: void solveNQueensUtil(int n, int curRow, int upc, int ld, int rd, int& totalCnt) { if(curRow == n) { totalCnt++; return; } for(int j = 0; j < n; ++j) { int curNum = 1<<j; if(curNum & (ld | rd | upc)) continue; solveNQueensUtil(n, curRow+1, upc|curNum, (ld|curNum)>>1, (rd|curNum)<<1, totalCnt); } } int totalNQueens(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function int totalCnt = 0; solveNQueensUtil(n, 0, 0, 0, 0, totalCnt); return totalCnt; } };
相关文章推荐
- LeetCode : N-Queens II
- N-Queens II
- N-Queens II
- LeetCode | N-Queens II
- N-Queens II
- [LeetCode] N-Queens II
- LeetCode OJ算法题(五十一):N Queens II
- N-Queens II
- Leetcode:N-Queens II
- N-Queens II
- LeetCode 52.N-Queens II
- [LeetCode][JavaScript]N-Queens II
- leetcode 052 —— N-Queens II
- N-Queens II
- LeetCode---N-Queens II
- leetcode:N-Queens II
- Leet Code 52 N-Queens II - N皇后问题 - Java
- leetcode N-Queens II
- LeetCode 52. N-Queens II 题解(C++)
- 89. Gray Code \ 51. N-Queens \ 52. N-Queens II