正文
增加 13 行删除 13 行
86 行未改动8788899091929394959697989945 行未改动14514614714814915015115215348 行未改动20220320420520620720820921011 行未改动22222322422522622722822923010 行未改动24124224324424524624724824914 行未改动26426526626726826927027127222 行未改动29529629729829930030130230330430530630726 行未改动334335336337338339340341342104 行未改动全部展开44744844945045145245345445515 行未改动47147247347447547647747847948048148248348448548618 行未改动86 行未改动int n;vector<vector<long long> > m;Mtr () {n = 0;}Mtr (int x) {n = x;m = vector<vector<long long> >(n, vector<long long>(n, 0));}};```对于矩阵乘法,我们可以通过重载运算符来实现:45 行未改动比如斐波那契的递推式,正常递推是 $O(n)$ 的:$$F_i =\begin{cases}1&i=1,2\\F_{i-1}+F_{i-2}& \text{Otherwise.}\end{cases}48 行未改动F_{i-2}\\F_{i-1}\end{pmatrix}=\begin{pmatrix}F_{i-1}\\F_i11 行未改动再根据 $F_{i}=F_{i-1}+F_{i-2}$ 就可以得到:$$A =\begin{pmatrix}0&1\\1&1\end{pmatrix}10 行未改动F_{i-2}\\F_{i-1}\end{pmatrix}=\begin{pmatrix}F_{i-1}\\F_i14 行未改动1\\1\end{pmatrix}=\begin{pmatrix}F_{n-1}\\F_n22 行未改动int n;vector<vector<long long> > m;Mtr () {n = 0;}Mtr (int x) {n = x;m = vector<vector<long long> >(n, vector<long long>(n, 0));}};Mtr operator*(Mtr x, Mtr y) {Mtr ans = Mtr(x.n);for (int i = 0; i < ans.n; i++)26 行未改动cout << 1 << endl;elsecout << (fpow(A, n - 2) * B).m[1][0] << endl;return 0;}```# 4.高斯消元104 行未改动全部展开```cpp#include <iostream>#include <cstdio>#include <cmath>#include <vector>#include <cstring>#include <algorithm>using namespace std;15 行未改动vector<double> operator*(vector<double> x, double y) {vector<double> ans((int)x.size());for (int i = 0; i < (int)ans.size(); i++)ans[i] = x[i] * y;return ans;}bool Gauss() {for (int i = 0; i < n; i++) {if (abs(a[i][i]) < 1e-9)return false;a[i] = a[i] * (1.0 / a[i][i]);for (int j = 0; j < n; j++)if (i != j)a[j] = a[j] - a[i] * a[j][i];}return true;18 行未改动86 行未改动8788899091929394959697989945 行未改动14514614714814915015115215348 行未改动20220320420520620720820921011 行未改动22222322422522622722822923010 行未改动24124224324424524624724824914 行未改动26426526626726826927027127222 行未改动29529629729829930030130230330430530630726 行未改动334335336337338339340341342104 行未改动全部展开44744844945045145245345445515 行未改动47147247347447547647747847948048148248348448548618 行未改动86 行未改动int n;vector<vector<long long> > m;Mtr () {n = 0;}Mtr (int x) {n = x;m = vector<vector<long long> >(n, vector<long long>(n, 0));}};```对于矩阵乘法,我们可以通过重载运算符来实现:45 行未改动比如斐波那契的递推式,正常递推是 $O(n)$ 的:$$F_i =\begin{cases}1&i=1,2\\F_{i-1}+F_{i-2}& \text{Otherwise.}\end{cases}48 行未改动F_{i-2}\\F_{i-1}\end{pmatrix}=\begin{pmatrix}F_{i-1}\\F_i11 行未改动再根据 $F_{i}=F_{i-1}+F_{i-2}$ 就可以得到:$$A =\begin{pmatrix}0&1\\1&1\end{pmatrix}10 行未改动F_{i-2}\\F_{i-1}\end{pmatrix}=\begin{pmatrix}F_{i-1}\\F_i14 行未改动1\\1\end{pmatrix}=\begin{pmatrix}F_{n-1}\\F_n22 行未改动int n;vector<vector<long long> > m;Mtr () {n = 0;}Mtr (int x) {n = x;m = vector<vector<long long> >(n, vector<long long>(n, 0));}};Mtr operator*(Mtr x, Mtr y) {Mtr ans = Mtr(x.n);for (int i = 0; i < ans.n; i++)26 行未改动cout << 1 << endl;elsecout << (fpow(A, n - 2) * B).m[1][0] << endl;return 0;}```# 4.高斯消元104 行未改动全部展开```cpp#include <iostream>#include <cstdio>#include <cmath>#include <vector>#include <cstring>#include <algorithm>using namespace std;15 行未改动vector<double> operator*(vector<double> x, double y) {vector<double> ans((int)x.size());for (int i = 0; i < (int)ans.size(); i++)ans[i] = x[i] * y;return ans;}bool Gauss() {for (int i = 0; i < n; i++) {if (abs(a[i][i]) < 1e-9)return false;a[i] = a[i] * (1.0 / a[i][i]);for (int j = 0; j < n; j++)if (i != j)a[j] = a[j] - a[i] * a[j][i];}return true;18 行未改动