bzoj1770: [Usaco2009 nov]lights Light

Source: Internet
Author: User
Tags bitset

Gaussian elimination solution or equations, and then burst search ... %%%ZYF http://www.cnblogs.com/zyfzyf/p/4059245.html Read the note only to understand%%%

#include <cstdio> #include <cstring> #include <bitset> #include <iostream> #include < algorithm>using namespace std; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i-- ) #define CLR (x,c) memset (x,c,sizeof (x)) int read () {int X=0;char C=getchar (), while (!isdigit (c)) C=getchar (), while ( IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x;} const int Nmax=37;const int inf=0x7f7f7f7f;bitset<nmax>a[nmax];int ans[nmax],res=inf,tot=0,n,m;void Gauss (int N , int m) {REP (i,1,n) {int j;for (j=i;j<=n&&!a[j][i];j++), if (j>n) continue;if (j!=i) swap (a[i],a[j]); REP (J,i+1,n) if (A[j][i]) a[j]^=a[i];}} void Dfs (int x) {if (tot>=res) return, if (!x) {res=min (res,tot); return;} if (A[x][x]) {int t=a[x][n+1]; REP (I,x+1,n) if (A[x][i]) t^=ans[i];ans[x]=t;if (t) tot++;d FS (x-1), if (t) tot--;} Else{ans[x]=0;dfs (x-1); ans[x]=1;tot++;d FS (x-1); tot--;}} int main () {N=read (), m=read (); int u,v; REP (I,1,n) A[i].reset (), a[i][i]=a[i][n+1]=1; REP (i,1,m) U=read (), V=read (), A[u][v]=a[v][U]=1; Gauss (n,n+1);d FS (N);p rintf ("%d\n", res); return 0;}

  

1770: [Usaco2009 nov]lights light Time limit:10 Sec Memory limit:64 MB
submit:712 solved:347
[Submit] [Status] [Discuss] 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.

Input

* First line: The whole number of two spaces separated: N and M.

* Second to m+1: each line has two integers separated by a space, indicating that the two beacon lights are connected together by an endless line. There is not a single side that will appear twice.

Output

The first line: A single integer that indicates that you need to press the number of open items at least when you want to turn all the lights on.

Sample Input5 6
1 2
1 3
4 2
3 4
2 5
5 3

Input Details:

A total of five beacon lights. The light 1, the light 4 and the light 5 are connected with the light 2 and the light 3.

Sample Output3

Input Details:

Press the Open on the light 1, the light 4, and the light 5. HINT Source

Gold

[Submit] [Status] [Discuss]

bzoj1770: [Usaco2009 nov]lights Light

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.