传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers 1, 2, . . . , n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle sho…
UVA - 524 Prime Ring Problem Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers into each circle separately, and the sum of number…
题意 把1到n这n个数以1为首位围成一圈 输出全部满足随意相邻两数之和均为素数的全部排列 直接枚举排列看是否符合肯定会超时的 n最大为16 利用回溯法 边生成边推断 就要快非常多了 #include<cstdio> using namespace std; const int N = 50; int p[N], vis[N], a[N], n; int isPrime(int k) { for(int i = 2; i * i <= k; ++i) if(k % i == 0)…
Prime Ring Problem A ring is composed of n (even number) circles as shown in diagram. Put natural numbers into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle should always…
dfs练习题,我素数打表的时候j=i了,一直没发现实际上是j=i*i,以后可记住了.还有最后一行不能有空格...昏迷了半天 我的代码(紫书上的算法) #include <bits/stdc++.h> using namespace std; int bk[110]; int num[110]; int vis[110]; int n; void db() { for(int i=2;i*i<=100;i++) if(!bk[i]) for(int j=i*i;j<=100;j+=i…
HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tempter of the Bone [从零开始DFS(1)] -DFS四向搜索/奇偶剪枝 HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] -DFS四向搜索变种 HDOJ(HDU).1016 Prime Ring Problem (…