# Usaco 3.3 TEXT Eulerian tour in cows on parade a little understanding

Source: Internet
Author: User

Farmer John has the types of cows:black Angus and white jerseys. While marching from their cows to market the other day, John's wife Farmeress Joanne, noticed that all possibilities O F Four successive black and white cows (e.g., BBBB, BBBW, BBWB, BBWW, ..., wwww) were present. Of course, some of the combinations overlapped others.

Farmer John has two kinds of cows: one is Black Angus, the other is white Zessis. When he drove 19 of his cows to the market the next day, Joanna, his wife and female farmer, noticed the order of 16 of all 4 black and white cows (e.g. black black black, black black and white, black and white black, black black, ...), all appeared in vain. Of course, some permutations are covered with each other.

Given N (2 <= n <=), find the minimum length sequence of cows such that every combination of n successive black a nd white cows occurs on that sequence.

The input has an n (2 <= n <= 15), which finds a string of minimum-length black-and-white cows arranged in a sequence of all black and white cows of the n length.

Analysis:the vertices of the graph is the possibilities of N-1 cows. Being at a node corresponds to the last N-1 cows matching the node in color. That's, for N = 4, and if the last 3 cows were WBWand then you were at the WBW node. Each node have out-degree of 2, corresponding to adding a black or white cow to the end of the sequence. In addition, each node had in-degree of 2, corresponding to whether the cow just before the last N-1 cows was black or whit E.

Analysis: The vertices of this figure are n-1 lengths of all possible cows ordered. When you are in a vertex you are quite the last n-1 cow in this cow color matching string. That is to say, for n=4, if the last three cows are arranged in the color "white and black", then you are in the "white black and white" this point. Each point has two degrees-the equivalent of adding white or black cattle to the back of the string. In addition, each point has two degrees-equivalent to the last n-1 of a cow before the color is black or white.

The graph is strongly connected, and the in-degree of each node equals it out-degree, so the graph has a Eulerian circuit .

The graph is strongly connected, and each graph has an entry equal to the degree of each point, so the graph has a Euler loop.

The sequence corresponding to the Eulerian circuit are the sequence of N-1 cows of the first node in the circuit, followed By cows corresponding to the color of the edge.

This string is equivalent to the first Euler loop of the n-1, followed by a cow that is the color of the edge.

If I tell my English teacher that I love translating English pages on weekends, will she praise me?

I personally feel that the translation of this problem is also a little unintelligible.

And the last "side of the color" a little bit of a problem, because this problem if you do Euler should not be the record side, is the record point, I put the idea of this problem slightly change, but the effect is unchanged, easy to understand. hope is not a misunderstanding ...

We create a new Black dot B, a white point w, and find that the description in the analysis is equivalent to a graph with a Euler loop nature.

Looking for the process can be abstracted into this, "WBW" after adding a B to the "BWB", "WBW" after adding a W to the "BWW", and then do the Euler circuit, equivalent to n-1 only black and white cows in all possible order after the addition of B or W to form two new strings, So the last loop string that we get is the answer.

But since we have to go through every side of the line, then the dot (or white dot) to which point is no longer related "because we are a bit of our own assumptions, So we can assume in our consciousness that WBW after B is the other point is BWB because the path must have gone through, the slightest need to consider this into the program " blue Word just to help understand

In fact, we just want to casually find a n-1 long string, can be all initialized to WWW,BBB and the like, put in front, such as test instructions, write the euro-pull circuit can be solved

Obviously, there seems to be no such problem in Usaco ... Because there is no way to find the problem on the internet ... I hope to be as patient as I can finish reading those English materials the last person to meet this problem will not be confused ...

At the same time if we only need to output the length, can use this stream of consciousness to prove that the black and white two points each pass 2^ (n-1) times, because black and white two points so is 2^n, and finally add n-1 so the answer is (2^n) +n-1,n=4 when the answer is 19 and the question is described in the same

Usaco 3.3 TEXT Eulerian tour in cows on parade a little understanding

Related Keywords:

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.