Hdu2894 Problem Solving report debruijin

Source: Internet
Author: User
Debruijin

Time Limit: 4000/2000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 321 accepted submission (s): 205


Problem description the surface of the rotary drum is divided into M slices (M = 8 ). In the figure, the shadow area is made of conductive material, and the blank area is made of insulating material. The terminal A, B, and C are 3 (k = 3) either grounding or not grounding is represented by binary signal 0 or 1. Therefore, the position of the drum can be expressed by a binary signal. How can I select the eight slices of material to obtain a different binary signal for each slice to be switched, that is, the 8 numbers between 111 and can be obtained every week.



Now we divide the surface of the rotary drum into M slices, each of which is recorded as 0 or 1, so that any successive k Number ordered Groups (in the same direction) are different, for a fixed K, the maximum value of M can be reached, and any output of such an ordered group that meets the conditions.

 


Input each case input a number K (2 <= k <= 11), indicating the number of ground wires such as ABC shown in the figure.


Output each case outputs the maximum value that m can reach, and the smallest Lexicographic Order is an ordered group that meets the conditions, separated by spaces. There are no empty rows between cases. The output format of the ordered group is 00010111 (k = 3, and only one cycle (0001011100010111…) is output ......), And the beginning and end are connected ).


Sample Input

3
 


Sample output

8 00010111
 


Source2009 multi-university training contest 10-host
By nit

Like the previous question, in fact, 00 to 001 is actually unchanged and can be abstracted into points, while 000,001 is only one and can be abstracted into edges, this question can be made. A tree is created with 0-2 ^ (n-1)-1 as the number, with 2 ^ (n-1) nodes in total, if you add 0 or 1 to the end of a node and then remove the highest bit, a directed edge is connected between two nodes. Each edge in the figure represents a number. There are 2 ^ n numbers, and they are different! The question requires the smallest Lexicographic Order, then from 2 ^ (n-1-1 node, and each node first add 0 edge, followed by a side of 1, so that the final Lexicographic Order can be guaranteed to be the smallest. Or the Euler loop is a model, and the algorithm is the same. But here, why is it faster for me to submit an object to OJ than 10 ms? I don't understand this!

# Include <iostream> # include <stdio. h ># include <vector> using namespace STD; struct tree {int V; int ID; int to; int flag ;}; int step; vector <tree> P [35000]; bool re [35000]; int path [35000]; void DFS (int u) {for (INT I = 0; I <p [u]. size (); I ++) {If (! Re [p [u] [I]. id]) {re [p [u] [I]. id] = true; DFS (P [u] [I]. to); path [step ++] = P [u] [I]. flag ;}} int main () {int I, k, n, TT; tree temp; while (~ Scanf ("% d", & K) {n = 1 <(k-1); // printf ("% d n \ n", N ); for (I = 0; I <= N; I ++) P [I]. clear (); for (I = 0; I <n; I ++) {TT = (I <1) -(I & (1 <(K-2) <1); // printf ("% d TT \ n", TT ); tt = TT % N; temp. to = tt; temp. id = I <1; temp. V = I; temp. flag = 0; P [I]. push_back (temp); Re [temp. id] = false; TT + = 1; // printf ("% d TT \ n", TT, DFS starts from 0. Note that TT = TT % N; temp. V = I; temp. to = tt; temp. id = I <1 | 1; temp. flag = 1; Re [temp. id] = false; P [I]. push_back (temp);} Step = 0; DFS (n-1); printf ("% d", n <1); for (I = Step-1; I >= 0; I --) {printf ("% d", path [I]);} printf ("\ n");} return 0 ;}

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.