矩阵乘法时如果当前位为零就跳过亲测 60pts→100pts
60pts
Matrix operator*(const Matrix &op){
if(C != op.R){
std::cout << "Matrix 乘法时,第一个的列数要和第二个的行数相同";
printf("\n %lld, %lld\n", C, op.R);
exit(-1);
}
Matrix Answer;
Answer.R = R;
Answer.C = op.C;
memset(Answer.Mat, 0, sizeof(Answer.Mat));
For(i, 1, R){
For(k, 1, C){
For(j, 1, op.C){
Answer.Mat[i][j] += Mat[i][k] * op.Mat[k][j];
Answer.Mat[i][j] %= mod;
}
}
}
return Answer;
}
100pts
Matrix operator*(const Matrix &op){
if(C != op.R){
std::cout << "Matrix 乘法时,第一个的列数要和第二个的行数相同";
printf("\n %lld, %lld\n", C, op.R);
exit(-1);
}
Matrix Answer;
Answer.R = R;
Answer.C = op.C;
memset(Answer.Mat, 0, sizeof(Answer.Mat));
For(i, 1, R){
For(k, 1, C){
if(Mat[i][k])
For(j, 1, op.C)
if(op.Mat[k][j]){
Answer.Mat[i][j] += Mat[i][k] * op.Mat[k][j];
Answer.Mat[i][j] %= mod;
}
}
}
return Answer;
}