题意:
思路:
A×C=B⊙C
∑k=1nAi,k∗Ck,j=Bi,j∗Ci,j
对于1 < = j < = n
(A1,1C1,j+A1,2C2,j+……+A1,nCn,j)%2=B1,jC1,j
01的加法和取余2 22相当于异或。
式子变成了
(A1,1C1,j⊕A1,2C2,j⊕…⊕A1,nCn,j)=B1,jC1,j
相当于解一个异或线性方程组,对于1 < = j < = n 中,是相互独立的。最后2 总 自 由 元 个 数 2^{总自由元个数}2
总自由元个数
就是答案。
如果A 1 , 1 = B 1 , j则a 1 , 1 = 0,这样右侧的结果位都是0;A1,1!=B1,j,则a 1 , 1 = 1
代码:
// Problem: Matrix Equation // Contest: NowCoder // URL: https://ac.nowcoder.com/acm/contest/10662/A // Memory Limit: 524288 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll>PLL; typedef pair<int, int>PII; typedef pair<double, double>PDD; typedef pair<string,string>PSS; #define I_int ll inline ll read(){ll x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;} inline void write(ll x){if (x < 0) x = ~x + 1, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + '0');} #define read read() #define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define multiCase int T;cin>>T;for(int t=1;t<=T;t++) #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i<(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) ll ksm(ll a, ll b,ll mod){ll res = 1;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;} const int maxn=2010; const double pi = acos(-1); ll n,m=31; ll a[210][210],g[210]; int A[210][210],B[210][210]; const int mod=998244353; int Gauss(int n,int m) { int r, c; for(r = 0, c = 0; c < n; c++) { int t = -1; for(int i = r; i < m; i++) { if(a[i][c]) { t = i; break; } } if(t==-1) continue; for(int i = c; i < n; i++)///交换 { swap(a[t][i], a[r][i]); } for(int i = r + 1; i < m; i++) { if(a[i][c]) for(int j = c; j <n; j++) { a[i][j] = a[i][j] ^ a[r][j]; } } r++; } return n-r; } void solve() { n=read; for(int i=0;i<n;i++) for(int j=0;j<n;j++) A[i][j]=read; for(int i=0;i<n;i++) for(int j=0;j<n;j++) B[i][j]=read; ll cnt=0; for(int j=0;j<n;j++){ for(int i=0;i<n;i++){ for(int k=0;k<n;k++){ a[i][k]=A[i][k]; } a[i][n]=0; if(A[i][i]==B[i][j]) a[i][i]=0; else a[i][i]=1; } ll tot=Gauss(n,n); if(tot<0){ puts("0"); return ; } else{ cnt+=tot; } } cout<<ksm(2,cnt,mod)<<endl; } int main() { int _;_=1; while(_--) solve(); return 0; }