1 条题解
-
0
C :
#include<stdio.h> int main() { int n; while((scanf("%d",&n))!=EOF) { if(n==0) break; int a[16]={1,0,0,2,10,4,40,92,352,724,2680,14200,73712,365596,2279184,14772512}; printf("%d\n",a[n-1]); } return 0; }
C++ :
#include<iostream> #include<algorithm> #include<cstring> #include<ctime> #include<cmath> #include<string> #include<cstdio> using namespace std; const int N = 16; int c[N], a[2*N], b[2*N], m[N][N], ans[N+1], n, res; void dfs(int r) { if(r == n) { ++res; return; } for(int i = 0; i < n; ++i) { if(c[i] || a[r+i] || b[i-r+n-1] || m[r][i]) continue; c[i] = a[i+r] = b[i-r+n-1] = m[r][i] = 1; dfs(r+1); c[i] = a[i+r] = b[i-r+n-1] = m[r][i] = 0; } } int main() { for(int i = 1; i < 16; ++i) { res = 0; n = i; memset(m, 0, sizeof(m)); memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c)); dfs(0); ans[i] = res; } while(scanf("%d", &n),n) { printf("%d\n", ans[n]); } return 0; }
- 1
信息
- ID
- 655
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者