Problems switch poj1830 [Gaussian elimination]

In fact, the first reaction is a two-way BFS, $ 2 ^ {14} $ searches, and more testing, should be able to before, but I was helpless two-way BFS just wrote a title, had not written.

The sequence of operation of the lamp was found not influence the results, since the operation is equivalent to a fixed operation position xor, xor can be easily exchanged, the order does not matter.

So depending on whether each lamp is operated. The amount set for the unknowns $ x_i $. Equation can then be designed, for each lamp, with a

$begin \text{xor} x_1 a_{1,1} \text{xor} x_2 a_{2,1} \text{xor} ... \text{xor} x_n a_{n,1} = end$

Is the initial state of each lamp through his XOR (exclusive OR of the lamp is operating by $ $ I $ I $ affect lights the lamp, take $ 0 / $ 1), and finally obtain the final state.

The $ begin $ status to the right to go early. High extinction modeled, and then starting with the first unknown arc line.

Finally, we asked how many kinds of programs, that is, the number of free entries can easily take $ 0 / $ 1, then the answer is $ 2 ^ {} $ the number of free entries. Otherwise, the whole right side of the equation is zero coefficients $ 1 $ no solution.

Thank hkk morning to tell me infinitely many solutions and no solution judge, or I'll knock one afternoon.

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 #define dbg(x) cerr << #x << " = " << x <<endl
 7 using namespace std;
 8 typedef long long ll;
 9 typedef double db;
10 typedef pair<int,int> pii;
11 template<typename T>inline T _min(T A,T B){return A<B?A:B;}
12 template<typename T>inline T _max(T A,T B){return A>B?A:B;}
13 template<typename T>inline char MIN(T&A,T B){return A>B?(A=B,1):0;}
14 template<typename T>inline char MAX(T&A,T B){return A<B?(A=B,1):0;}
15 template<typename T>inline void _swap(T&A,T&B){A^=B^=A^=B;}
16 template<typename T>inline T read(T&x){
17     x=0;int f=0;char c;while(!isdigit(c=getchar()))if(c=='-')f=1;
18     while(isdigit(c))x=x*10+(c&15),c=getchar();return f?x=-x:x;
19 }
20 int A[33],bin[33];
21 int T,n,x,y,c,ans;
22 
23 int main(){//freopen("test.in","r",stdin);//freopen("test.out","w",stdout);
24     for(register int i=0;i<=30;++i)bin[i]=1<<i;
25     read(T);while(T--){
26         read(n);ans=0;
27         memset(A,0,sizeof A);
28         for(register int i=1;i<=n;++i)read(x),A[i]|=x<<n;
29         for(register int i=1;i<=n;++i)read(x),A[i]^=x<<n;
30         while(read(x),read(y))A[y]|=bin[x-1];
31         for(register int i=1;i<=n;++i)A[i]|=bin[i-1];
32         for(x=1,c=1;c<=n;++c){//dbg(c),dbg(x),dbg(A[x]);
33             for(y=x;y<=n&&!(bin[c-1]&A[y]);++y);
34             if(y==n+1)continue;
35             swap(A[x],A[y]);
36             for(register int l=1;l<=n;++l)if((l^x)&&(A[l]&bin[c-1]))A[l]^=A[x];
37             ++x;
38         }
39         for(register int i=x;i<=n;++i){
40             if(A[i]&bin[n])ans=-114514;
41             else ++ans;
42         }
43         if(ans<0)puts("Oh,it's impossible~!!");
44         else printf("%d\n",1<<ans);
45     }
46     return 0;
47 }
View Code

 

Guess you like

Origin www.cnblogs.com/saigyouji-yuyuko/p/11493189.html