Description
On the Tanabata festival, Vani led CL's hand and happily walked through the bright lights and cheerful atmosphere. At this time, suddenly appeared in front of a too drum talent machine, and sitting at the machine is just being elite team members Xlk, Poet_shy and Lydrainbowcat rescued out of the Applepi. See two people to too drum up people have interest, Applepi decisive Flash, so CL picked up the drum stick ready to challenge. However, even in the ordinary difficulty, CL's pedestrian nature has been fully exposed. The end of a song, not only did not pass, even the drums are not spiritual. Vani very sorry, decided to help staff repair drums.
The main component of a drum is a sensor with a circle of M. Each sensor has two operating states, open and closed, denoted by 1 and 0 respectively. Obviously, a continuous check of k sensors in a clockwise direction from a different position can be achieved by 01 strings with a m length of K. Vani know that this m 01 string should be different from each other. And the drum design is very sophisticated, m will take the maximum possible value. Now that Vani has learned the value of K, he wants you to find the value of M, and give the sensor arrangement scheme with the smallest dictionary order.
First of all, if you do a second question on the basis of knowing the answer to the first question, there is an obvious way to do this is DFS
But the complexity of time. The answer to the first question <=2^k, every one backtracking is 2^ (2^k)//Don't think about it ...>_<
Let's imagine if this retrospective has any particular nature.
We treat each attached K number as a point, with two out of each point, because the next number may be 0, maybe 1.
In the same way is also two, because the previous number may be 0 may be 1
Then we find out the degrees of each point = in degrees, and this is exactly the Eulerian graph criterion.
So the original is a Eulerian graph, there must be a European pull circuit
So at random the first question is bound to take the biggest 2^k
For the second question, or the original DFS, but think about it will find that the complexity of the time is actually O (n)
Because there's no chance of turning back, except in the case of self-ring.
You might say, "There's no way to go in front of a place?"
Apparently, it's not in the Eulerian graph nature.
So almost a line pulls out the answer.
{
Euler Diagram
}program bzoj3033;Constmaxn=2050;varAns,k,i:longint; b:array[-1.. Maxn]of Longint; used:array[-1.. Maxn]of boolean;function dfs (p,step:longint): Boolean;beginifNot used[p] then exit (false); USED[P]:=false; B[step]:=p >> (K-1); ifStep=ans Then Exit (true); ifDFS (P <<1and (ans-1), step+1) Then exit (true); ifDFS (P <<1and (ans-1)+1, step+1) Then exit (true); USED[P]:=true; Exit (false); End;begin Readln (k); Ans:=1; Fillchar (Used,sizeof(used),true); fori:=1to K Doans:=ans*2; Write (ans,' '); DFS (0,1); fori:=1To ans Dowrite (b[i]); end.
[BZOJ3033] Taiko Drum Talent | Eulerian graph