标签:code ++i 矩阵 mat eof style amp mem 模板
struct mat { LL ma[sz][sz]; inline mat() { memset(ma, 0, sizeof ma); } inline mat operator+(const mat & T) const { mat res; for (int i = 0; i < sz; ++i) for (int j = 0; j < sz; ++j) res.ma[i][j] = (ma[i][j] + T.ma[i][j] + MOD) % MOD; return res; } inline mat operator-(const mat& T) const { mat res; for (int i = 0; i < sz; ++i) for (int j = 0; j < sz; ++j) res.ma[i][j] = (ma[i][j] - T.ma[i][j]) % MOD; return res; } inline mat operator*(const mat& T) const { mat res; for (int i = 0; i < sz; ++i) for (int j = 0; j < sz; ++j) for (int k = 0; k < sz; ++k) res.ma[i][j] = (res.ma[i][j] + ma[i][k] * T.ma[k][j]) % MOD; return res; } inline mat operator^(LL x) const { mat res, bas; for (int i = 0; i < sz; ++i) res.ma[i][i] = 1; for (int i = 0; i < sz; ++i) for (int j = 0; j < sz; ++j) bas.ma[i][j] = ma[i][j]; while (x) { if (x & 1) res = res * bas; bas = bas * bas; x >>= 1; } return res; } }
不错呀
标签:code ++i 矩阵 mat eof style amp mem 模板
原文地址:https://www.cnblogs.com/passione-123456/p/11956988.html