Bzoj1770: [usaco 2009 Nov] Lights release

Source: Internet
Author: User
Description

She and her secret are playing in their cowshed. However, it was never a human error. Suddenly, the electricity in the cowshed jumped, and all the traffic was shut down. She was a very small girl. She felt terrible, painful, and anxious when she reached out and couldn't see her thumb in the dark. She hopes that you can help her and start all the tokens again! Only then can she try again with her secret! A total of N (1 <= n <= 35) cowshed operators, ranging from 1 to n. These images are placed on a very large network. With M (1 <= m <= 595), there are magical undirected links. Each segment is connected to two consecutive links. Each Shard has an active relationship. When you press the turn-on function of a certain website, the website itself will change the changes that have been sent to the website. When a volume changes, it means that when a volume is on, the volume is closed. When a volume is on, this region is opened. Ask the minimum number of Enis to be pressed before all partitions can be re-opened. The data protection certificate should have at least one service-based solution, so that all the licenses can be re-opened.

Question: http://www.lydsy.com/JudgeOnline/problem.php? Id = 1770

Question:

After reading the question, I found that it seems to be an exclusive or Gaussian yuan, and then I found that I don't seem to be able...

Worship the hzwer code...

In the end, I still need to search. Decisively copy the code.

Some comments are written in the code...

Note that f [I] [I] = 0 indicates that I is a free variable.

Code:

1 # include <cstdio> 2 3 # include <cstdlib> 4 5 # include <cmath> 6 7 # include <cstring> 8 9 # include <algorithm> 10 11 # include <iostream> 12 13 # include <vector> 14 15 # include <map> 16 17 # include <set> 18 19 # include <queue> 20 21 # include <string> 22 23 # define INF 1000000000 24 25 # define maxn 500 + 100 26 27 # define maxm 500 + 100 28 29 # define EPS 1e-10 30 31 # define ll long 32 33 # define PA pair <int, I NT> 34 35 # define for0 (I, n) for (INT I = 0; I <= (n); I ++) 36 37 # define for1 (I, n) for (INT I = 1; I <= (n); I ++) 38 39 # define for2 (I, x, y) for (INT I = (X ); I <= (y); I ++) 40 41 # define for3 (I, x, y) for (INT I = (x); I> = (y ); I --) 42 43 # define mod 1000000007 44 45 using namespace STD; 46 47 inline int read () 48 49 {50 51 int x = 0, F = 1; char CH = getchar (); 52 53 While (CH <'0' | ch> '9') {If (CH = '-') F =-1; ch = getchar ();} 54 55 while (Ch >='0' & Ch <= '9') {x = 10 * x + CH-'0'; CH = getchar ();} 56 57 Return x * F; 58 59} 60 int n, m, TOT; 61 int Mn = inf; 62 int f [45] [45], ANS [45]; 63 void Gauss () 64 {65 for1 (I, n) 66 {67 Int J = I; 68 while (j <= N &&! F [J] [I]) J ++; 69 If (j> N) continue; 70 If (J! = I) for1 (k, n + 1) Swap (F [I] [K], F [J] [k]); 71 for2 (J, I + 1, n) 72 If (F [J] [I]) 73 for2 (K, I, n + 1) 74 f [J] [k] ^ = f [I] [k]; 75} 76} 77 inline void DFS (INT X) 78 {79 if (TOT> = Mn) return; // optimize pruning 80 If (! X) {Mn = min (Mn, TOT); return;} // end 81 If (F [x] [x]) // has been restricted whether to press 82 {83 int T = f [x] [n + 1]; 84 for2 (I, x + 1, n) if (F [x] [I]) t ^ = ans [I]; 85 ans [x] = T; 86 If (t) tot ++; 87 DFS (x-1); // continue Deep Search 88 If (t) tot --; // restore, trace 89} 90 else // free variable 91 {92 ans [x] = 0; DFS (x-1); // assume that 93 ans [x] = 1 is not switched by this lamp; TOT ++; DFS (x-1); Tot --; // suppose to switch 94} 95} 96 97 int main () 98 99 {100 101 freopen ("input.txt ", "r", stdin); 102 103 freopen ("output.txt", "W", stdout); 104 105 N = read (); M = read (); 106 for1 (I, n) f [I] [I] = 1, F [I] [n + 1] = 1; 107 for1 (I, m) {int x = read (), Y = read (); F [x] [Y] = f [y] [x] = 1;} 108 Gauss (); DFS (n); 109 printf ("% d \ n", Mn); 110 111 return 0; 112 113}
View code

 

 

 

Bzoj1770: [usaco 2009 Nov] Lights release

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.