ysyx_22040000 李心杨 Linux calcite 6.6.19 #1-NixOS SMP PREEMPT_DYNAMIC Fri Mar 1 12:35:11 UTC 2024 x86_64 GNU/Linux 16:26:21 up 4 days 3:32, 2 users, load average: 0.85, 0.91, 0.95
32 lines
617 B
C
32 lines
617 B
C
#include <benchmark.h>
|
|
|
|
static unsigned int FULL;
|
|
|
|
static unsigned int dfs(unsigned int row, unsigned int ld, unsigned int rd) {
|
|
if (row == FULL) {
|
|
return 1;
|
|
} else {
|
|
unsigned int pos = FULL & (~(row | ld | rd)), ans = 0;
|
|
while (pos) {
|
|
unsigned int p = (pos & (~pos + 1));
|
|
pos -= p;
|
|
ans += dfs(row | p, (ld | p) << 1, (rd | p) >> 1);
|
|
}
|
|
return ans;
|
|
}
|
|
}
|
|
|
|
static unsigned int ans;
|
|
|
|
void bench_queen_prepare() {
|
|
ans = 0;
|
|
FULL = (1 << setting->size) - 1;
|
|
}
|
|
|
|
void bench_queen_run() {
|
|
ans = dfs(0, 0, 0);
|
|
}
|
|
|
|
int bench_queen_validate() {
|
|
return ans == setting->checksum;
|
|
}
|