Description
You are given three n × n matrices A, B and C. Does the equation A × B = C hold true?
Input
The first line of input contains a positive integer n (n ≤ 500) followed by the the three matrices A, B and C respectively. Each matrix's description is a block of n × n integers.
It guarantees that the elements of A and B are less than 100 in absolute value and elements of C are less than 10,000,000 in absolute value.
Output
Output "YES" if the equation holds true, otherwise "NO".
Sample Input
2 1 0 2 3 5 1 0 8 5 1 10 26
Sample Output
YES
Hint
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 #include<ctime> 7 using namespace std; 8 int n,flag,a[501][501],b[501][501],c[501][501],A[501],B[501],C[501],v[501]; 9 int main() 10 {int i,j,k; 11 while (cin>>n) 12 { 13 flag=0; 14 for (i=1;i<=n;i++) 15 { 16 for (j=1;j<=n;j++) 17 scanf("%d",&a[i][j]); 18 } 19 for (i=1;i<=n;i++) 20 { 21 for (j=1;j<=n;j++) 22 scanf("%d",&b[i][j]); 23 } 24 for (i=1;i<=n;i++) 25 { 26 for (j=1;j<=n;j++) 27 scanf("%d",&c[i][j]); 28 } 29 srand(time(0)); 30 for (k=1;k<=60;k++) 31 { 32 for (i=1;i<=n;i++) 33 v[i]=rand()%2; 34 for (i=1;i<=n;i++) 35 { 36 B[i]=0; 37 for (j=1;j<=n;j++) 38 B[i]+=b[i][j]*v[j]; 39 } 40 for (i=1;i<=n;i++) 41 { 42 C[i]=0; 43 for (j=1;j<=n;j++) 44 C[i]+=c[i][j]*v[j]; 45 } 46 for (i=1;i<=n;i++) 47 { 48 A[i]=0; 49 for (j=1;j<=n;j++) 50 A[i]+=a[i][j]*B[j]; 51 } 52 for (i=1;i<=n;i++) 53 if (A[i]!=C[i]) 54 { 55 flag=1; 56 break; 57 } 58 if (flag) break; 59 } 60 if (flag) printf("NO\n"); 61 else printf("YES\n"); 62 } 63 }