随机一个行向量 P ,
判断
当然有一定概率判断失误。。。
时间复杂度: O(n2)
蒙特·卡罗方法? 我不知道,先留坑。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <iostream>
#include <algorithm>
template<class Num>void read(Num &x)
{
char c; int flag = 1;
while((c = getchar()) < '0' || c > '9')
if(c == '-') flag *= -1;
x = c - '0';
while((c = getchar()) >= '0' && c <= '9')
x = (x<<3) + (x<<1) + (c-'0');
x *= flag;
return;
}
template<class Num>void write(Num x)
{
if(x < 0) putchar('-'), x = -x;
static char s[20];int sl = 0;
while(x) s[sl++] = x%10 + '0',x /= 10;
if(!sl) {putchar('0');return;}
while(sl) putchar(s[--sl]);
}
const int maxn = 505, Base = 10;
typedef long long Array[maxn][maxn];
#define REP(__i,__start,__end) for(int __i = (__start); __i <= (__end); __i++)
int n;
Array A, B, C;
long long P[maxn], Q[maxn], AnsL[maxn], AnsR[maxn];
void init()
{
REP(i, 1, n)
REP(j, 1, n)
read(A[i][j]);
REP(i, 1, n)
REP(j, 1, n)
read(B[i][j]);
REP(i, 1, n)
REP(j, 1, n)
read(C[i][j]);
}
bool check()
{
REP(i, 1, n)
{
P[i] = rand()%Base;
Q[i] = AnsL[i] = AnsR[i] = 0;
}
REP(i, 1, n)
REP(k, 1, n)
AnsR[i] += P[k] * C[k][i];
REP(i, 1, n)
REP(k, 1, n)
Q[i] += P[k] * A[k][i];
REP(i, 1, n)
REP(k, 1, n)
AnsL[i] += Q[k] * B[k][i];
REP(i, 1, n)
if(AnsL[i] != AnsR[i]) return false;
return true;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("3318.in","r",stdin);
freopen("3318.out","w",stdout);
#endif
srand(998244353);
while(scanf("%d", &n) != EOF)
init(), puts(check()?"YES":"NO");
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}