题解:http://www.matrix67.com/blog/archives/266
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 |
#include <cstdio> int n,ans,upperlim; void
test( int
row, int
ld, int
rd) { int
pos,p; if
(row!=upperlim) { pos=upperlim&(~(row|ld|rd)); while (pos) { p=pos&(~pos+1); pos=pos-p; test(row|p,(ld|p)<<1,(rd|p)>>1); } } else
ans++; } int
main() { int
i; while ( scanf ( "%d" ,&n)&&n) { upperlim=(1<<n)-1; ans=0; test(0,0,0); printf ( "%d\n" ,ans); } return
0; } |
原文:http://www.cnblogs.com/forever97/p/3543090.html