Test instructions: let you construct a ring string, composed of binary 0,1, and then each interception of different k, composed of the number is not the same, now give you a number k, and then construct the dictionary order of the smallest string, so that the value of the x length to meet the intercept is not the same.
Analysis: This topic is not very good understanding, understanding is simple. can be violent search.
Its model is a Euler circuit, the first x length of the 0,1 string consisting of the maximum number of n=2^x-1.
How to construct a Euler loop model, assuming first by n vertex number (0,1,2...N), now arbitrarily give a vertex number F, I give up the front one, and then add 0 or 1 to the next one is the ring string, then the value of the second value is tmp1= (f<<1) & (( 1 << N)-1), as well as TMP2 = tmp1|1, so I give all f with TMP1 and tmp2, such vertices have a forward edge, construct a graph, and then structure the string we just found a Euler loop in the diagram is a string, So we just run once for the Euler loop, but keep the dictionary order to a minimum, so be careful here
In fact, combining this idea of brute force search program is simpler.
Brute Force Code:
#include <iostream>#include <cstdio>#include <cstring>#include <vector>using namespace STD;Const intN = the;BOOLok[1<<N]; vector<int>VvoidDfsintXintN) {intTMP1 = x*2; TMP1 = tmp1& ((1<<n)-1);/// overall left 1 bits, control range n bit, last one 0|1 intTMP2 = tmp1+1; while(!OK[TMP1]) {OK[TMP1] =true; DFS (TMP1,N); V.push_back (0); } while(!OK[TMP2]) {OK[TMP2] =true; DFS (TMP2,N); V.push_back (1); }}intMain () {intN while(~scanf("%d", &n)) {memset(OK,false,sizeof(OK)); Dfs0, n);printf("%d",1<<N); for(intI=0; i<n-1; i++)Putchar(' 0 '); for(intI=v.size ()-1; i>=n-1; i--)printf("%d", V[i]);puts(""); V.clear (); }return 0;}
The drum Euro Loop (hdoj2894debruijin&poj1392)