---
# System prepended metadata

title: martix
tags: [Code]

---

---
tags: Code
---

# martix


速度較慢
```cpp = 
struct matrix {
	bool legal = 0;
	int row, col;
	vector<vector<ll>> vc;
	matrix(int a, int b) : row(b), col(a) {vc.assign(a, vector<ll> (b, 0)); legal = 1;}

	auto operator * (matrix mat) {
		matrix cmp(col, mat.row);
		if(row != mat.col) {cmp.legal = 0; return cmp;}
		for(int i = 0; i < cmp.col; i++) {
			for(int j = 0 ;j < cmp.row; j++) {
				for(int k = 0; k < row; k++) {
					cmp.vc[i][j] =(cmp.vc[i][j] + (vc[i][k] * mat.vc[k][j] % mod)) % mod;
				}
			}
		}
		return cmp;
	}
	
	bool chk() {return legal;}
	void out () {for(auto &i : vc) {for(auto &j : i) cout<< j << ' '; cout << endl;}}
	void read() {for(auto &i  : vc) for(auto &j : i) cin >> j;}
};
```  

```cpp = 
const int mts = 3; //matrix max size

struct matrix {
	int row, col;
	ll ar[mts][mts];
	matrix(int a, int b) : row(b), col(a) {MEM(ar);}
	matrix() : row(0), col(0) {MEM(ar);};

	inline matrix operator * (matrix mat) {
		matrix cmp(col, mat.row);
		for(int i = 0; i < col; i++) {
			for(int j = 0 ;j < mat.row; j++) {
				for(int k = 0; k < row; k++) {
					cmp.ar[i][j] = (cmp.ar[i][j] + ar[i][k] * mat.ar[k][j] % mod) % mod;
				}
			}
		}
		return cmp;
	}
	bool chk(matrix mat) {return row == mat.col;}
	void read() {for(int i = 0 ;i < col; i++) for(int j = 0; j < row; j++) cin >> ar[i][j];}
};

```