卡常技巧
查看原帖
卡常技巧
1231078
bjzjh楼主2025/7/25 10:47

矩阵乘法时如果当前位为零就跳过亲测 60pts100pts60 \,\texttt{pts} \rightarrow 100\,\texttt{pts}

60pts60 \,\texttt{pts}

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;
	}

100pts100\,\texttt{pts}

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;
	}
2025/7/25 10:47
加载中...