这题n三方显然会GG...
运用矩阵乘法的性质A*B*R=A*(B*R)=C*R,于是随机化出一个一列的R,就可以把复杂度降低成n方...大概率是不会错的
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<algorithm> #define ll long long using namespace std; const int maxn=510,inf=1e9; typedef int mtx[maxn][maxn]; int n,m,x,y,z,tot; mtx f,a,b,c; void read(int &k) { int f=1;k=0;char c=getchar(); while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar(); while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar(); k*=f; } void mul(mtx &a,mtx b) { mtx c;memset(c,0,sizeof(c)); for(int i=1;i<=n;i++) for(int j=1;j<=1;j++) for(int k=1;k<=n;k++) c[i][j]+=a[i][k]*b[k][j]; memcpy(a,c,sizeof(c)); } int main() { srand(19260817); for(int i=1;i<=500;i++)f[i][1]=1+rand()%1000; while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) read(a[i][j]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) read(b[i][j]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) read(c[i][j]); mul(b,f);mul(c,f);mul(a,b); int flag=0; for(int i=1;i<=n;i++) if(a[i][1]!=c[i][1]) { flag=1; break; } printf("%s ",flag?"No":"Yes"); } return 0; }