hdoj 1575 Tr A 51nod oj 1113 矩阵快速幂【矩阵快速幂】
来源:互联网 发布:python配置文件怎么写 编辑:程序博客网 时间:2024/05/20 19:15
传送门:1575
矩阵快速幂--与一般快速幂一样--
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{int n;long long shu[12][12];node operator * (node &b){node c;c.n=n;for (int i=1;i<=n;i++)for (int j=1;j<=n;j++){c.shu[i][j]=0;for (int k=1;k<=n;k++)c.shu[i][j]=(c.shu[i][j]+shu[i][k]*b.shu[k][j])%9973;}return c;}}a,b,c,ans;void slove(){int n,k;long long s=0;scanf("%d%d",&a.n,&k);for (int i=1;i<=a.n;i++)for (int j=1;j<=a.n;j++)scanf("%lld",&a.shu[i][j]);ans.n=a.n;for (int i=1;i<=a.n;i++)for (int j=1;j<=a.n;j++)ans.shu[i][j]=0;for (int i=1;i<=a.n;i++)ans.shu[i][i]=1;while (k){if (k%2)ans=ans*a;a=a*a;k/=2;}for (int i=1;i<=a.n;i++)s=(s+ans.shu[i][i])%9973;printf("%lld\n",s);}int main(){int t;scanf("%d",&t);while (t--)slove();return 0;}
传送门:1113
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;long long mod=1000000007;struct node{int n;long long shu[120][120];node operator * (node &b){node c;c.n=n;for (int i=1;i<=n;i++)for (int j=1;j<=n;j++){c.shu[i][j]=0;for (int k=1;k<=n;k++)c.shu[i][j]=(c.shu[i][j]+shu[i][k]*b.shu[k][j])%mod;}return c;}}a,b,c,ans;void slove(){int n,k;long long s;scanf("%d%d",&a.n,&k);for (int i=1;i<=a.n;i++)for (int j=1;j<=a.n;j++)scanf("%lld",&a.shu[i][j]);ans.n=a.n;for (int i=1;i<=a.n;i++)for (int j=1;j<=a.n;j++)ans.shu[i][j]=0;for (int i=1;i<=a.n;i++)ans.shu[i][i]=1;while (k){if (k%2)ans=ans*a;a=a*a;k/=2;}for (int i=1;i<=a.n;i++){for (int j=1;j<a.n;j++)printf("%lld ",ans.shu[i][j]);printf("%lld\n",ans.shu[i][a.n]);}}int main(){slove();return 0;}
0 0
- hdoj 1575 Tr A 51nod oj 1113 矩阵快速幂【矩阵快速幂】
- hdoj 1575 Tr A 【矩阵快速幂】
- hdoj-1575-Tr A【矩阵快速幂】
- hdoj 1575 Tr A 【矩阵快速幂】
- hdoj 1575 Tr A 【矩阵快速幂】
- HDOJ-----1575---Tr A矩阵快速幂
- hdoj 1575 Tr A (矩阵快速幂)
- HDOJ 1575 Tr A 矩阵快速幂
- HDOJ 1575 Tr A (矩阵快速幂)
- hdoj 1575 Tr A(矩阵快速幂,模板题)
- Tr A 矩阵快速幂
- hdu 1575Tr A 矩阵快速幂
- HDU 1575 Tr A(矩阵快速幂)
- HDU 1575 Tr A (矩阵快速幂)
- HDU 1575-Tr A(矩阵快速幂)
- HDU 1575 Tr A (矩阵快速幂)
- HDU - 1575 Tr A(矩阵快速幂)
- hdu 1575 Tr A(矩阵快速幂)
- 【垂直搜索引擎搭建00】说在前面的话
- AsyncTask原理分析
- Recommender System Fragment 2
- 通讯录动态开辟版本
- 忘记mysql root用户密码的解决办法(skip-grant-tables)
- hdoj 1575 Tr A 51nod oj 1113 矩阵快速幂【矩阵快速幂】
- 【POJ】Jungle Roads
- HDU1596 find the safest road(floyd)
- 想成为嵌入式程序员应知道的0x10个基本问题
- Java中可变长参数的使用及注意事项
- SQL内连接、左外链接、右外连接、交叉链接区别
- Advanced Fruits hd 1503
- "Mac OS X"想要进行更改。键入管理员的名称和密码以允许执行此操作("Mac OS X"想使用系统钥匙串)
- hdu 5823color II 状压(2016多校第八场1003)