HDU5015 233 Matrix(矩阵快速幂)
来源:互联网 发布:淘宝网充值 编辑:程序博客网 时间:2024/05/21 01:57
题目:
233 Matrix
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2180 Accepted Submission(s): 1274
Problem Description
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233333 ... in the same meaning. And here is the question: Suppose we have a matrix called 233 matrix. In the first line, it would be 233, 2333, 23333... (it means a0,1 = 233,a0,2 = 2333,a0,3 = 23333...) Besides, in 233 matrix, we got ai,j = ai-1,j +ai,j-1( i,j ≠ 0). Now you have known a1,0,a2,0,...,an,0, could you tell me an,m in the 233 matrix?
Input
There are multiple test cases. Please process till EOF.
For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 109). The second line contains n integers, a1,0,a2,0,...,an,0(0 ≤ ai,0 < 231).
For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 109). The second line contains n integers, a1,0,a2,0,...,an,0(0 ≤ ai,0 < 231).
Output
For each case, output an,m mod 10000007.
Sample Input
1 112 20 03 723 47 16
Sample Output
234279972937Hint
Source
2014 ACM/ICPC Asia Regional Xi'an Online
Recommend
hujie | We have carefully selected several similar problems for you: 6022 6021 6020 6019 6018
这道题一看数据范围是10的九次方,那么普通方法肯定行不通,这时候我们用矩阵快速幂。
关于构造矩阵:http://blog.csdn.net/u011721440/article/details/39401515
代码:
#include <cstdio>#include <cstring>#include <cctype>#include <string>#include <set>#include <iostream>#include <stack>#include <cmath>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define mod 10000007#define N 3#define M 1000000+10#define ll long longusing namespace std;int n;struct Mat{ ll mat[12][12]; void init() { memset(mat,0,sizeof(mat)); } void E() { init(); for(int i=0;i<n;i++) mat[i][i]=1; } void show() { printf("debug\n"); for(int i=0;i<=n+1;i++,puts("")) for(int j=0;j<=n+1;j++) printf("%lld ",mat[i][j]); printf("Over\n"); }};Mat operator *(Mat a,Mat b){ Mat res; res.init(); for(int i=0;i<=n+1;i++) for(int j=0;j<=n+1;j++) for(int k=0;k<=n+1;k++) res.mat[i][j]+=a.mat[i][k]*b.mat[k][j],res.mat[i][j]%=mod; return res;}Mat ksm(Mat a,int b){ Mat res; res.E(); while(b>0) { if(b&1) res=a*res; a=a*a; b>>=1; } return res;}Mat getmat(){ Mat res; res.init(); for(int i=0;i<n;i++) for(int j=0;j<=i;j++) res.mat[i][j]=1; for(int i=0;i<=n;i++) res.mat[n][i]=10; for(int i=0;i<=n+1;i++) res.mat[n+1][i]=1; return res;}int main(){ int m; while(scanf("%d%d",&n,&m)!=EOF) { Mat ori; ori.init(); ori.mat[0][n]=23; ori.mat[0][n+1]=3; for(int i=n-1;i>=0;i--) scanf("%lld",&ori.mat[0][i]); Mat res=ori*ksm(getmat(),m); printf("%lld\n",res.mat[0][0]); } return 0;}
0 0
- hdu5015 233 Matrix 矩阵快速幂
- HDU5015-233 Matrix(矩阵快速幂)
- HDU5015 233 Matrix(矩阵快速幂)
- hdu5015 233 Matrix(矩阵快速幂)
- 【矩阵快速幂】 hdu5015 233Matrix
- HDU5015 233 Matrix(矩阵快速幂)
- hdu5015 233 Matrix 矩阵快速幂 矩阵构造方法
- 【hdu5015】233 Matrix——矩阵快速幂
- 解题报告:HDU5015 233 Matrix 矩阵快速幂
- hdu5015——233 Matrix(矩阵快速幂)
- HDU5015---233 Matrix (矩阵快速幂(递推))
- hdu5015---233 Matrix(矩阵)
- 矩阵快速幂-HDU5015
- 233 Matrix(hdu5015 矩阵)
- hdu5015(矩阵快速幂)
- hdu5015 233 Matrix(构造矩阵)
- hdu5015 矩阵快速幂233(好题)
- HDU5015-233 Matrix
- 谈谈自己对REST、SOA、SOAP、RPC、ICE、ESB、BPM知识汇总及理解
- 使用IntelliJ IDEA 通过maven插件运行tomcat7
- 剑指offer----包含min函数的栈
- Linux下快速静态编译Qt以及Qt动态/静态版本共存
- 刷简书阅读量
- HDU5015 233 Matrix(矩阵快速幂)
- Runtime.getRuntime().exec执行scp失败
- 使用tensorflow实现简单的多分类问题
- 《挑战程序设计竞赛》2.1 最基础的穷竭搜索
- css 新特征
- 自定义view(二):onDraw 之 Paint
- 浅析数据库(DB)、操作数据存储(ODS)和数据仓库(DW)的区别与联系
- 计算器原码、反码和补码和位移的一些总结
- VS2017 创建NET Core 1.1 Web项目,发布后找不到引用的js文件