1016:
A ring is compose of n circles as shown in diagram. Put natural number 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 should always be 1.
大意:
一个环由n个圈组成的如图表中所示。把自然数1~n个数单独的放进每个圆圈里去,并且在两个相邻圆圈的数字之和应该是一个素数。
注意:第一个圆的数字应该总是1。

输入Input:
n (0 < n < 20).
输出:
The output format is shown as sample below. Each row represents a series of circle numbers in the ring beginning from 1 clockwisely and anticlockwisely. The order of numbers must satisfy the above requirements. Print solutions in lexicographical order.
You are to write a program that completes above process.
Print a blank line after each case.
输出在如样例中所示。每一行展示的数字从1开始顺时针方向直至逆时针方向。输出的这些数字必须满足上述的条件。输出时按字典序。
在每一个样例后面再加一个空行。
(注意:这里

题目要求在一个由n个圈组成的环形结构中,从1开始顺时针和逆时针填充自然数,使得相邻两数之和为素数。第一个圈的数字固定为1,解决方案需要满足字典序排列并进行DFS搜索。在搜索过程中,通过标记避免重复路径,并在递归过程中检查相邻数字和是否为素数。注意最后的回溯操作,保持book数组的状态正确。
最低0.47元/天 解锁文章
2507

被折叠的 条评论
为什么被折叠?



