标签:des style blog http java color
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25700 Accepted Submission(s): 11453
#include <stdio.h> #include <string.h> int visited[25], foot[25]; int x[11]= {3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}; int Prime(int a, int b) { int mark = 0; for(int i = 0; i<11; i++) { if( a+b == x[i] ) { mark = 1; break; } } return mark; } void DFS(int n, int m) { if(m == n) { if(Prime(foot[1], foot[n])) { for(int i = 1; i<n; i++) { printf("%d ", foot[i]); } printf("%d\n", foot[n]); //printf("\n"); } } else { for(int i = 1; i<=n; i++) { if(visited[i]) continue; if(Prime(foot[m], i) == 1) { foot[m+1] = i; visited[i] = 1; DFS(n, m+1); visited[i] = 0; } } } } int main() { int n, k = 1; while(scanf("%d", &n)!=EOF) { if(n<=0 || n>=20) break; memset(visited, 0, sizeof(visited)); visited[1] = 1; foot[1] = 1; printf("Case %d:\n", k++); DFS(n, 1); printf("\n"); } return 0; }
hdu 1016 Prime Ring Problem (简单DFS),布布扣,bubuko.com
hdu 1016 Prime Ring Problem (简单DFS)
标签:des style blog http java color
原文地址:http://www.cnblogs.com/fengxmx/p/3855108.html