n皇后的算法的补充程序,在线等 n皇后问题是使用回溯算法求解的代表问题?我想要C语言版的! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这题对于很多程序员来说都是偏难的 看着有人几行代码就解决了,我看都看不懂public class EightQueen { static int sum = 0, upperlim = 1; private static void test(int row, int ld, int rd) { if (row != upperlim) { int pos = upperlim & ~(row | ld | rd); while (pos != 0) { int p = pos & -pos; pos -= p; test(row + p, (ld + p) << 1, (rd + p) >> 1); } } else{ sum++; } } public static void main(String[] args) { int n = 5; long tm = System.currentTimeMillis(); if ((n < 1) || (n > 32)) { System.out.println(" heh..I can't calculate that."); System.exit(-1); } System.out.println(n + " Queens"); upperlim = (upperlim << n) - 1; test(0, 0, 0); System.out.println("Number of solutions is " + sum + ", Useing " + (System.currentTimeMillis() - tm) / 1000 + " seconds"); }} java如何获取调用者的实例 求 java 小程序代码!(分...不是问题 ) jforum的问题 问个关于tomcat服务器的问题(回答有分) 关于swing编写多国语言切换的问题 应用程序drawImage画图 如何:勾选“全选”后,每行的checkbox都选中? 请问下面代码中的 i 跟 j 最后分别是多少 有没有对Class:Observer,熟悉的? 调查:大家都用哪个Java语言编程? HashMap报空指针,求帮助啊!!! 为什么aop 切面不能切入自定义标签的doTag()方法
public class EightQueen {
static int sum = 0, upperlim = 1;
private static void test(int row, int ld, int rd) {
if (row != upperlim) {
int pos = upperlim & ~(row | ld | rd);
while (pos != 0) {
int p = pos & -pos;
pos -= p;
test(row + p, (ld + p) << 1, (rd + p) >> 1);
}
} else{
sum++;
}
}
public static void main(String[] args) {
int n = 5;
long tm = System.currentTimeMillis();
if ((n < 1) || (n > 32)) {
System.out.println(" heh..I can't calculate that.");
System.exit(-1);
}
System.out.println(n + " Queens");
upperlim = (upperlim << n) - 1;
test(0, 0, 0);
System.out.println("Number of solutions is " + sum + ", Useing "
+ (System.currentTimeMillis() - tm) / 1000 + " seconds");
}
}