首页 > TAG信息列表 > HDU1016
HDU1016 Prime Ring Problem DFS
Problem Description 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. IDay2-M-Prime Ring Problem-HDU1016
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. Inputn (0 < n <hdu1016(基础dfs和打表的应用)
基础dfs ,用打表法避免了素数判断程序 #include <iostream> #include <stdio.h> #include <algorithm> using namespace std; int prime[40]={0,1,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},n=0;//素数打表,因为n最大是20,所以只要打到40