Bzoj 1770 [Usaco2009 nov]lights Light "Gaussian elimination element"

Source: Internet
Author: User

Description

Becky and her bedroom are playing games in their bullpen. But the day does not from the person, suddenly, the source of the barn jump shutter, all the lights are closed. Baby is a very small girl, in the endless darkness that reaches her thumb, she is horrified, miserable and hopeless. She wants you to help her, to start all the lights again! She can continue to play the game with her bedroom! A total of n (1 <= n <= 35) Beacon lights in the bullpen, 1 to N. These lights are placed in a very complex network. With M (1 <= m <= 595) It's a magical infinity, with two beacon lights attached to each side. Every beacon Light has a start. When a beacon light is pressed, the beacon light itself, and all the lights that are connected to the beacon light, are changed. State change means that when a beacon light is open, the beacon Light is turned off, and when a beacon is concerned, the beacon light is opened. Ask at least how many to press to get all the lights back open. There is at least one push-to-open scheme that allows all lights to be reopened.

Solution

Test instructions: There are n operations, each operation can change the status of some lights, asked to open all the lights required by the minimum number of operations, the start of the lights are off

Apparently two of the same operation makes no sense.

It is only possible to choose or not to choose, the state of the lamp is only two, open or extinguished, is obviously the solution of an XOR equation

A relational table can be listed by test instructions

AIJ indicates whether I J can change state with each other and then have XOR or Equation a11*x1 xor a12*x2 xor ... XOR A1N*XN = 1

A21*x1 xor A22*x2 xor ... XOR A2N*XN = 2

............................................................

Am1*x1 xor Am2*x2 xor ... XOR AMN*XN = 1

The solution can be solved by using the Gaussian elimination element.

However, the problem requires a minimal solution.

When will the solution not be the only one?

If there is an item XI, the last equation to be solved is 0*xi = 0

That is, when the first and subsequent equations of the XI coefficients are all 0, it is said that Xi free (xi either 0 or 1, can derive a solution of the entire equation set)

In the matrix is embodied as f[I [i]=0

At this point XI takes 0 or 1 to change the value of the other XJ

Change the value of the Ans=∑xi

This time enumerate the values of Xi and update the answer

1#include <bits/stdc++.h>2 3 #defineMAXN 35+54 #defineSet (a B) memset (A, (b), sizeof (a))5 #defineFR (i,a,b) for (ll i= (a), _end_= (b); i<=_end_;i++)6 #defineRF (I,b,a) for (ll i= (a), _end_= (b); i>=_end_;i--)7 8 using namespacestd;9 TentypedefLong Longll; One  A intF[MAXN][MAXN]; - intans[maxn],res=Int_max; - intn,m; the  - voidGauss () - { -Fr (I,1, N) { +     intj=i; -      while(J<=n &&!f[j][i]) J + +; +     if(j>n)Continue; A     if(i!=j) atFr (P,1, n+1) - swap (f[i][p],f[j][p]); -Fr (J,1, N) -       if(I!=j &&F[j][i]) -Fr (P,1, n+1) -f[j][p]^=F[i][p]; in   } - } to  + voidDfsintXintCost ) - { the   if(Cost>=res)return ; *   if( !x) { $res=Cost ;Panax Notoginseng     return ; -   } the   if(F[x][x]) { +     intt=f[x][n+1]; AFr (i,x+1, N) the       if(F[x][i]) t^=Ans[i]; +ans[x]=T; -DFS (X-1, cost+t); $   } $   Else{ -ans[x]=0; -DFS (X-1, cost); theans[x]=1; -DFS (X-1, cost+1);Wuyi   } the } -  Wu intMain () - { About #ifndef Online_judge $Freopen ("1770.in","R", stdin); -Freopen ("1770.out","W", stdout); - #endif -CIN >> N >>m; AFr (I,1, N) +f[i][i]=f[i][n+1]=1; theFr (I,1, M) { -     intx, y; $CIN >> x >>y; thef[x][y]=f[y][x]=1; the   } the Gauss (); theDFS (N,0); -cout <<Res; in   return 0; the}

Bzoj 1770 [Usaco2009 nov]lights Light "Gaussian elimination element"

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.