顺便把这个代码也放下出来吧 具体原理大家百度去~
// 查找(位运算方法)
int sum = 0, upperlimit = 1,p;
public void search3(int row, int ld, int rd)
{
if (row != upperlimit)
{
int pos = upperlimit & ~(row | ld | rd);
while (pos != 0)
{
p = pos & -pos;
pos -= p;
search3(row + p, (ld + p) << 1, (rd + p) >> 1);
}
}
else
{
sum++;
}
}
main
upperlimit = (upperlimit << q.n) - 1;
search3(0, 0, 0);