蒟蒻请求巨佬帮助!

P3216 [HNOI2011] 数学作业

@[顾瑀丶](/space/show?uid=153898) %%%tql
by zh_dou @ 2019-06-07 18:29:29


```cpp martix operator * (const martix & a,const martix & b) { martix res; memset(res.f,0,sizeof res.f); for(int k = 1;k <= 3;k ++) for(int i = 1;i <= 3;i ++) for(int j = 1;j <= 3;j ++) res.f[i][j] = (res.f[i][j] + res.f[i][k] * res.f[k][j] % m) % m; return res; } ``` 你初始化成0之后怎么加怎么乘都是0吧 @[顾瑀丶](/space/show?uid=153898)
by 我惠美如画 @ 2019-06-07 18:35:40


```cpp martix operator * (const martix & a,const martix & b) { martix res; memset(res.f,0,sizeof res.f); for(int k = 1;k <= 3;k ++) for(int i = 1;i <= 3;i ++) for(int j = 1;j <= 3;j ++) res.f[i][j] = (res.f[i][j] + res.a[i][k] * res.b[k][j] % m) % m; return res; } ```
by zh_dou @ 2019-06-07 18:36:33


$ res.a[i][k] * res.b[k][j]$ 不是 $ res.f[i][k] * res.f[k][j]$
by zh_dou @ 2019-06-07 18:37:41


orzorz
by ΦωΦ @ 2019-06-07 18:42:25


@[顾瑀丶](/space/show?uid=153898) %%%tql
by __wfx @ 2019-06-07 18:57:49


@[我惠美如画](/space/show?uid=146702) 矩阵快速幂就是这样写的 ~~~cpp martix operator * (const martix & a , const martix & b) { martix res; memset(res.f,0,sizeof res.f ); for(int k = 1;k <= n;k ++) for(int i = 1;i <= n;i ++) for(int j = 1;j <= n;j ++) res.f[i][j] = (res.f[i][j] + a.f[i][k] * b.f[k][j] % mod) % mod; return res; } ~~~
by Treaker @ 2019-06-07 19:02:13


@[顾瑀丶](/space/show?uid=153898) 矩阵快速幂中$res$应初始为单位元矩阵 就是 $$ \left\{ \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \right\} $$
by __wfx @ 2019-06-07 19:04:26


@[顾瑀丶](/space/show?uid=153898) 你没发现这个和你代码里的不一样吗
by 我惠美如画 @ 2019-06-07 19:04:54


@[我惠美如画](/space/show?uid=146702) 发现了 , 但还是不对
by Treaker @ 2019-06-07 20:13:29


| 下一页