标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13319 Accepted Submission(s): 6028
#include<cstdio> #include<cstring> #include<algorithm> int C[50], vis[3][50], tot, n; void dfs(int cur) { if(cur==n) tot++; else for(int i=0; i<n; i++) { if(!vis[0][i]&& !vis[1][cur+i] && !vis[2][cur-i+n]) { C[cur] = i; vis[0][i] = vis[1][i+cur]=vis[2][cur-i+n] = 1; dfs(cur+1); vis[0][i] = vis[1][i+cur]=vis[2][cur-i+n] = 0; } } } int main() { while(scanf("%d", &n)!=EOF&&n) { tot = 0; memset(vis, 0, sizeof(vis)); dfs(0); printf("%d\n", tot); } return 0; }
无奈上面的代码依然超时。 然而小恪机智的发现,此题的数据是这么的亲民! 就10个数。 用上面的程序打表飘过。
#include<cstdio> int C[11] = {0, 1, 0, 0 ,2 ,10 ,4 ,40 ,92 ,352, 724}; int main() { int n; while(scanf("%d", &n)!=EOF&&n) { printf("%d\n", C[n]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/acm1314/p/4747357.html