Poj1830 is one of the few Chinese questions! I don't need to ask for a visit from Google.
Description
There are n identical switches, each of which is associated with some switches. Whenever you turn a switch on or off, other switches associated with this switch will also change accordingly, that is, the status of these associated switches will change to off if it is turned on, and if it is turned off, it will change to on. Your goal is to make the last n switches to a specific State after several switching operations. For any switch, you can only perform one switch operation at most. Your task is to calculate how many methods can reach the specified state. (Excluding the switch operation order ). Well, for each light bulb, all the differences that will affect his switch (change to 1, do not change to 0) or whether he needs to change; therefore, for each light bulb, we can list an exclusive or equation. The unknown element is required or not to change each switch. The coefficient indicates whether the switch is related to the light bulb. The rest is Gaussian. (Each equation can be represented by a longint using bitwise operations ). Wa has been used many times. Pay attention to the following points: 1. A switch corresponds to the light bulb at the beginning; 2. the uncertainty is determined until the last equation (I for I: = 1 to n-1); 3. O should be capitalized. I wa dozens of times! Fortunately, it's a vest. Code: Program ex2; <br/> var <br/> A: array [0 .. 30] of longint; <br/> I, j, k, n, l, ANS, task: longint; <br/> begin <br/> readln (task ); <br/> for task: = 1 to task do begin <br/> fillchar (A, sizeof (A), 0); <br/> readln (n); ans: = 0; <br/> for I: = 1 to n do read (A [I]); <br/> for I: = 1 to n do begin <br/> Read (j); A [I]: = (a [I] xor j) + 1 <I; <br/> end; <br/> Read (I, j); <br/> while I <> 0 do begin <br/> A [J]: = A [J] Or (1 <I); <br/> Read (I, j); <br/> end; <br/> J: = 1; <br/> for I: = 1 to n do begin <br/> K: = J; <br/> while not odd (A [k]> I) and (k <= N) do Inc (k); <br/> if k <= n then begin <br/> A [0]: = A [k]; A [k]: = A [J]; A [J]: = A [0]; <br/> for L: = J + 1 to n do <br/> If Odd (A [l]> I) then a [l]: = A [l] XOR A [J]; <br/> Inc (j); <br/> end; <br/> ans: = N-J + 1; <br/> for J: = J to n do if odd (A [J]) Then ans: =-1; <br/> If ans> = 0 then writeln (1 <NS) <br/> else writeln ('oh, it''s impossible ~!! '); <Br/> end.