struct Matrix { __int64 v[110][110]; Matrix() { memset(v, 0, sizeof(v)); } Matrix operator *(const Matrix B) // 重载的速度比写独立的函数慢点。 { int i, j, k; Matrix C; for(i = 0; i <= tot; i ++) for(j = 0; j <= tot; j ++) for(k = 0; k <= tot; k ++) { C.v[i][j] = (C.v[i][j] + v[i][k] * B.v[k][j]) % MOD; } return C; } };
Matrix mtPow(Matrix A, int k) // 用位运算代替递归求 A^k。 { int i; Matrix B; for(i = 0; i <= tot; i ++) { B.v[i][i] = 1; } while(k) { if(k & 1) B = B * A; A = A * A; k >>= 1; } return B; }
原文地址:https://www.cnblogs.com/WTSRUVF/p/10294217.html
时间: 2024-10-14 06:21:54