锤子手机火了 老罗英语荒了# PDA - 掌中宝
i*y
1 楼
请问下面有一行:
pos = upper & (~(row | ld |rd));
这里为什么要upper&?upper不都是1吗?
class Solution {
public:
int cnt,upper;
int totalNQueens(int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
cnt = 0;
upper = (1< Queen(0,0,0);
return cnt;
}
void Queen(int row,int ld,int rd)
{
int pos,p;
if(row!=upper)
{
pos = upper & (~(row | ld |rd));
while(pos!=0)
{
p = pos & (-pos);
pos = pos - p;
Queen(row+p,(ld+p)<<1,(rd+p)>>1);
}
}
else ++cnt;
}
};
pos = upper & (~(row | ld |rd));
这里为什么要upper&?upper不都是1吗?
class Solution {
public:
int cnt,upper;
int totalNQueens(int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
cnt = 0;
upper = (1<
return cnt;
}
void Queen(int row,int ld,int rd)
{
int pos,p;
if(row!=upper)
{
pos = upper & (~(row | ld |rd));
while(pos!=0)
{
p = pos & (-pos);
pos = pos - p;
Queen(row+p,(ld+p)<<1,(rd+p)>>1);
}
}
else ++cnt;
}
};