The drum Euro Loop (hdoj2894debruijin&poj1392)

Source: Internet
Author: User

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&LT;&LT;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.