Describe
Analysis
Only a path of point 1 to N and a number of rings in the graph can be represented as all paths by XOR. So how many loops do you need to be able to make sure that all the paths are represented? In fact, it does not need a lot, because some rings can be different or get through other rings, just to ensure that the ring is independent of each other, there is a difference between the 22 sides (multiplier). Constructs a spanning tree, the statistic non-tree edge and the spanning tree formation ring can, at most only m-n+1 a ring. DFS implementations are available with a time complexity of O (M).
In combination with the above properties, it is possible to design a greedy statement: The x is represented as a binary number, from the high to the low enumeration, the current potential energy takes 1 to take 1.
- Enumerates the current bits from high to low;
- Select a number a[i] in the a array with the current bit 1], or 1 if there is no a[i];
- If the current bit of x is 0, then X=x xor a[i];
- All the current bits in the A array are 1 (a[j] and A[i] xor, A[j]=a[j] a[i], ext. 1).
The final x guarantee must be the largest, with a time complexity of O (NB). (n is the size of a array, and B is bits number)
- Read the above analysis went to play, the results several times WA. Then, in contrast to the Hzwer code, it was found that the elements he had selected in step 2 were not considered at the back of Step 2 o'clock.
- Why didn't you say anything in the information?
Change this place, you're right.
1 move directly to the left 62 will be an error. But once in a while it's OK ...
- What is the relationship between this problem and the Gaussian elimination element and the linear basis?
Code
https://code.csdn.net/snippets/619907
- Home: http://blog.csdn.net/qq_21110267
bzoj-2115-xor-wc2011