矩阵快速幂(特殊矩阵+优化)upc2604
来源:互联网 发布:idea java log4j使用 编辑:程序博客网 时间:2024/06/01 20:47
构造出的矩阵:
A1...
A1 A2...
A1 A2 A3...
A1 A2 A3 .........An
辅助矩阵:
1 2 3......n
0 1 2......n-1
0 0 1......n-2
0 0 0......1
矩阵式对称的可以只保留(A1,A2.......An)和(1,2,3,....n)进行优化,这样矩阵运算的时候只需要两重循环
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MOD=1000000007;int n,k;struct node{ long long a[2010]; void init(){memset(a,0,sizeof(a));}};node mul(node &a,node &b){ node tmp; tmp.init(); for(int i=0;i<n;i++) for(int j=0;j<=i;j++) { tmp.a[i]+=a.a[j]*b.a[i-j]; tmp.a[i]%=MOD; } return tmp;}node pow(node &a,int m){ node c; c.init(); c.a[0]=1; while(m) { if(m&1)c=mul(c,a); a=mul(a,a); m>>=1; } return c;}int main(){ //freopen("in.txt","r",stdin); while(scanf("%d",&n)!=EOF) { node x,y; x.init(); for(int i=0;i<n;i++)scanf("%lld",&x.a[i]); scanf("%d",&k); for(int i=0;i<n;i++)y.a[i]=i+1; node tmp=pow(y,k); tmp=mul(x,tmp); for(int i=0;i<n-1;i++) printf("%lld ",tmp.a[i]); printf("%lld\n",tmp.a[n-1]); } return 0;}
0 0
- 矩阵快速幂(特殊矩阵+优化)upc2604
- 矩阵快速幂优化
- 矩阵快速幂优化递推式
- foj 1692 矩阵快速幂&&循环矩阵优化
- hdu 2276 矩阵快速幂&&循环矩阵优化
- [hdu4965]矩阵快速幂优化 不规则矩阵相乘 模板
- 矩阵快速幂+优化LA3704(uva1386)
- HDU2604-- Queuing(矩阵快速幂优化)
- HDU 5318 (dp+矩阵快速幂优化)
- 矩阵乘法+快速幂优化递推式
- 矩阵快速幂优化的动态规划
- hdu4965——矩阵快速幂优化
- 矩阵快速幂,矩阵加法,矩阵乘法
- [矩阵快速幂] fzu 2117 特殊的数
- 转移矩阵+矩阵快速幂
- 矩阵乘法 矩阵快速幂
- 构造矩阵+矩阵快速幂
- 快速矩阵快速幂
- ios学习——网络操作
- 大河白银早评[2014年4月28日]
- APNS提供了两项基本的服务:消息推送和反馈服务
- ubuntu杂谈(一)----- ubuntu14.04 上安装ffmpeg
- 一直相信,每个人心里都住着一座城,那里生长着一片属于自己的原始森林,无论岁月如何侵蚀打磨
- 矩阵快速幂(特殊矩阵+优化)upc2604
- Linux软连接和硬链接
- QT:This application has failed to start because the application configuration is incorrect...
- [转载]Android学习synchronized(一)
- Spring 定时任务
- Android高手进阶教程(三)之----Android 中自定义View的应用.
- js note
- U盘无法启动ubuntu安装的解决办法
- 常用sql语句 语法