1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| template <class Type> void op (Type &x, Type &a, Type &b) { } template <class Type> struct Matrix { int n, m; Type w[N][N]; Matrix() { } Matrix(int x, int y) { n = x, m = y; } Matrix(int x, int y, Type k) { n = x, m = y; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) w[i][j] = i == j ? k : 0; } friend Matrix operator*(Matrix x, Matrix y) { Matrix res(x.n, y.m, Type(0)); for (int i = 1; i <= res.n; i++) for (int j = 1; j <= res.m; j++) for (int k = 1; k <= x.m; k++) op(res.w[i][j], x.w[i][k], y.w[k][j]); return res; } friend Matrix operator^(Matrix b, int k) { Matrix res(b.n, b.m, Type(1)); for (; k; k >>= 1, b = b * b) if (k & 1) res = res * b; return res; } };
|