标签:
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 39699 Accepted Submission(s): 17495
1 #include <cstdio> 2 #include <cstring> 3 4 int n; 5 bool pri[40] = {0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0}; 6 int a[25]; 7 bool vis[25]; 8 9 void dfs(int level) 10 { 11 if(level == n && pri[a[1]+a[n]]){ 12 for(int i = 1; i<n; ++i){ 13 printf("%d ",a[i]); 14 } 15 printf("%d\n",a[n]); 16 return; 17 } 18 for(int i = 2; i <= n; ++i){ 19 if(!vis[i] && pri[i+a[level]]){ 20 a[++level] = i; 21 vis[i] = true; 22 dfs(level); 23 vis[i] = false; 24 --level; 25 } 26 } 27 } 28 29 int main() 30 { 31 memset(vis,0,sizeof(vis)); 32 int cnt = 0; 33 while(~scanf("%d",&n)){ 34 printf("Case %d:\n",++cnt); 35 a[1] = 1; 36 dfs(1); 37 printf("\n"); 38 } 39 return 0; 40 }
标签:
原文地址:http://www.cnblogs.com/inmoonlight/p/5369125.html