Portal
$ N, m $ is given. Create a non-full $0 $ matrix of $ n \ times M $. All the grids meet the following conditions: it is an even sum of the weights of the top, bottom, and left grids. $ N, m \ Leq 40 $
You can list the differences or equations of $ n \ times M $ and $ n \ times M $ equations based on the conditions in the question. (The equations mean that all positions are $1 $ or $0 $, the answers in the rightmost column need to be generated in the sense of $ mod \, 2 $ through equations of different or mutual elimination ).
In theory, when the number of the same element and the number of equations is the same, each element has a unique solution. However, in the case of a solution, some of the equations are linearly related, which means they are eliminated to the end, some rows are changed to $0 $ (if not clearly, you can create a $3 \ times 3 $ and $4 \ times 4 $ table like $ vegetable chicken $ me ). We can set all $0 $ yuan (also called free yuan) in a row to $1 $, because they have no relationship with the final solution of the equation, then, we can launch the above step by step.
Because the complexity is $1600 ^ 3 $, the normal Gaussian elimination speed is very slow, so you can use fairy $ STL \, bitset $ to optimize
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 inline int read(){ 5 int a = 0; 6 bool f = 0; 7 char c = getchar(); 8 while(c != EOF && !isdigit(c)){ 9 if(c == ‘-‘)10 f = 1;11 c = getchar();12 }13 while(c != EOF && isdigit(c)){14 a = (a << 3) + (a << 1) + (c ^ ‘0‘);15 c = getchar();16 }17 return f ? -a : a;18 }19 20 const int dir[5][2] = {0,1,0,-1,1,0,-1,0,0,0};21 bitset < 1600 > gauss[1600] , ans;22 23 int main(){24 #ifdef LG25 freopen("3164.in" , "r" , stdin);26 freopen("3164.out" , "w" , stdout);27 #endif28 int M , N;29 cin >> M >> N;30 for(int i = 0 ; i < M ; i++)31 for(int j = 0 ; j < N ; j++)32 for(int k = 0 ; k < 5 ; k++)33 if(i + dir[k][0] >= 0 && i + dir[k][0] < M && j + dir[k][1] >= 0 && j + dir[k][1] < N)34 gauss[i * N + j][(i + dir[k][0]) * N + j + dir[k][1]] = 1;35 int now = 0;36 for(int i = 0 ; i < M * N ; i++){37 int j = now;38 while(j < M * N && !gauss[j][i])39 j++;40 if(j == M * N)41 continue;42 if(j != now)43 swap(gauss[now] , gauss[j]);44 while(++j < M * N)45 if(gauss[j][i])46 gauss[j] ^= gauss[now];47 now++;48 }49 for(int i = M * N - 1 ; i >= 0 ; i--){50 if(!gauss[i][i])51 ans[i] = 1;52 if(ans[i])53 for(int j = i - 1 ; j >= 0 ; j--)54 if(gauss[j][i])55 ans[j] = ans[j] ^ 1;56 }57 for(int i = 0 ; i < M ; i++){58 for(int j = 0 ; j < N ; j++){59 putchar(ans[i * N + j] + 48);60 putchar(‘ ‘);61 }62 putchar(‘\n‘);63 }64 return 0;65 }
Luogu1_4 cqoi2014 harmony matrix exclusive or Gaussian Element