标签:print row int [] ase pen += pow struct
template <typename Int>
struct Matrix {
Int m[M][M];
int row, column;
Matrix() {
for (int i = 0; i < M; i += 1)
for (int j = 0; j < M; j += 1)
m[i][j] = 0;
}
Matrix(int _r) : Matrix() {
row = _r, column = _r;
for (int i = 0; i < row; i += 1) f[i][i] = 1;
}
Matrix(int _r, int _c) : Matrix(){ row = _r, column = _c; }
Int* operator [](int row) const {
return (Int*)m[row];
}
void Show() {
puts("\nbegin matrix");
for (int i = 0; i < row; i += 1) {
for (int j = 0; j < column; j += 1)
printf("%.3f ", m[i][j]);
puts("");
}
puts("end matrix\n");
}
Matrix operator * (const Matrix& o) const {
Matrix res(Matrix(row, o.column));
for (int i = 0; i < row; i += 1)
for (int j = 0; j < o.column; j += 1) {
for (int k = 0; k < column; k += 1)
res.m[i][j] += m[i][k] * o.m[k][j];
}
return res;
}
Matrix operator ^ (int pow) const {
Matrix res(Matrix(row)), base(Matrix(row, row));
while (pow) {
if (pow & 1) res = res * base;
base = base * base;
pow >>= 1;
}
return res;
}
};
标签:print row int [] ase pen += pow struct
原文地址:https://www.cnblogs.com/qdscwyy/p/9903124.html