struct Matrix {
typedef long long ll;
const ll mod = 1000000007;
ll matrix[110][110];
//矩阵里的每一个数
ll line, colu;
//矩阵的行,列
Matrix operator *(const Matrix &b) const{
Matrix ans;
ans.line = line, ans.colu = b.colu;
for (int i = 1; i <= line; ++ i) {
for (int j = 1; j <= b.colu; ++ j) {
ans.matrix[i][j] = 0;
for (int k = 1; k <= colu; ++ k) {
ans.matrix[i][j] = (ans.matrix[i][j] + matrix[i][k] * b.matrix[k][j] % mod) % mod;
}
}
}
return ans;
} //矩阵乘法
bool operator ==(const Matrix &b) const{
if (colu != b.colu || line != b.line) return false;
for (int i = 1; i <= line; ++ i) {
for (int j = 1; j <= colu; ++ j) {
if (matrix[i][j] != b.matrix[i][j]) {
return false;
}
}
}
return true;
} //判断矩阵是否相等
bool operator !=(const Matrix &b) const{
if (colu != b.colu || line != b.line) return true;
for (int i = 1; i <= line; ++ i) {
for (int j = 1; j <= colu; ++ j) {
if (matrix[i][j] != b.matrix[i][j]) {
return true;
}
}
}
return false;
} //判断矩阵是否不相等
Matrix operator +(const Matrix &b) const{
Matrix ans;
ans.line = line, ans.colu = colu;
for (int i = 1; i <= line; ++ i) {
for (int j = 1; j <= colu; ++ j) {
ans.matrix[i][j] = matrix[i][j] + b.matrix[i][j];
}
}
return ans;
} //矩阵加
Matrix operator -(const Matrix &b) const{
Matrix ans;
ans.line = line, ans.colu = colu;
for (int i = 1; i <= line; ++ i) {
for (int j = 1; j <= colu; ++ j) {
ans.matrix[i][j] = matrix[i][j] - b.matrix[i][j];
}
}
return ans;
} //矩阵减
void operator =(const Matrix &b) {
line = b.line, colu = b.colu;
for (int i = 1; i <= line; ++ i) {
for (int j = 1; j <= colu; ++ j) {
matrix[i][j] = b.matrix[i][j];
}
}
return;
} //矩阵赋值
void MatrixPre(Matrix &a) {
for (int i = 1; i <= a.line; ++ i) {
for (int j = 1; j <= a.colu; ++ j) {
if (i == j) a.matrix[i][j] = 1;
else a.matrix[i][j] = 0;
}
}
return;
} //将矩阵a变成单位矩阵
Matrix MatrixQuickPower(Matrix const &mat, ll b) {
Matrix base = mat, ans;
ans.line = mat.line, ans.colu = mat.colu;
MatrixPre(ans);
while (b != 0) {
if ((b & 1) == 1) {
ans = ans * base;
}
base = base * base;
b >>= 1;
}
return ans;
} //矩阵快速幂
};
标签:封装,一系列,ll,colu,矩阵,ans,const,Matrix
From: https://www.cnblogs.com/jueqingfeng/p/17625417.html