HDU 5015 233Matrix (构造矩阵)
来源:互联网 发布:mac os x server 编辑:程序博客网 时间:2024/06/18 16:32
233 Matrix
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1399 Accepted Submission(s): 826
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
234279972937#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <algorithm>#include <vector>#include <queue>#include <cmath>#include <stack>#define LL long longusing namespace std;const long long MAXN = 15;const long long mod = 10000007;struct Matrix{ long long mat[MAXN][MAXN], n; Matrix(){memset(mat, 0, sizeof(mat));} Matrix operator * (Matrix & rhs) { Matrix res; res.n = n; for(long long i=1;i<=n;i++) { for(long long j=1;j<=n;j++) { for(long long k=1;k<=n;k++) { (res.mat[i][j] += (mat[i][k] * rhs.mat[k][j]) % mod) %= mod; } } } return res; }};Matrix pow_mod(Matrix a, long long b){ Matrix res; res.n = a.n; for(long long i=1;i<=a.n;i++) res.mat[i][i] = 1; while(b) { if(b & 1) res = res * a; a = a * a; b >>= 1; } return res;}long long a[MAXN], n, m;int main(){ while(scanf("%I64d%I64d", &n, &m)!=EOF) { for(long long i=1;i<=n;i++) scanf("%I64d", &a[i]); Matrix ans; ans.n = n + 2; for(long long i=1;i<=n + 1;i++) { ans.mat[i][1] = 10; for(long long j=2;j<=i;j++) { ans.mat[i][j] = 1; } } for(long long i=1;i<=n+1;i++) ans.mat[n+2][i] = 0; for(long long i=1;i<=n+2;i++) ans.mat[i][n+2] = 1; ans = pow_mod(ans, m); /* for(long long i=1;i<=n+2;i++) { for(long long j=1;j<=n+2;j++) cout << ans.mat[i][j] << ' '; cout <<endl; }*/ a[0] = 23, a[n+1] = 3; long long rs = 0; for(long long i=1;i<=n+2;i++) (rs += a[i-1] * ans.mat[n+1][i]) %= mod; printf("%I64d\n", rs); } return 0;}
0 0
- HDU 5015 233 Matrix (构造矩阵)
- HDU 5015 233Matrix (构造矩阵)
- HDU 5015 233 Matrix(构造矩阵)
- HDU 5015 - 233 Matrix (矩阵构造 矩阵快速幂)
- HDU - 5015 233 Matrix (矩阵构造)
- hdu 5015 233 Matrix(构造矩阵)
- hdu 5015 233 Matrix(矩阵构造加快速幂)
- hdu 5015 233 Matrix 线性序列构造矩阵快速幂
- hdu 5015 233 Matrix(西安网络赛1009)【构造矩阵】
- Hdu 5015 233 Matrix (矩阵乘法)
- hdu-5015-233 Matrix-矩阵
- hdoj 5015 233 Matrix(矩阵的构造)
- hdu5015 233 Matrix(构造矩阵)
- HDU 5015 233 Matrix(西安网络赛I题, 构造矩阵)
- HDU 5015 233 Matrix (矩阵快速幂)
- hdu 5015 233 Matrix(数学:矩阵快速幂)
- hdu 5015 233 Matrix (矩阵快速幂)
- hdu 5015 233 Matrix(矩阵快速幂)
- MVC三层模型(struts+spring+hibernate)总结
- 【2015更新】修改Host文件,让你的Google跑起来 2015 Google hosts(附秘密通道)
- 产品经理如何做好行业研究及竞争对手分析工作
- 1090. Highest Price in Supply Chain (25) -计层的BFS改进
- STL学习----入门(1)[unordered_map]
- HDU 5015 233Matrix (构造矩阵)
- 如何使Fiddler能捕获LoadRunner的http请求
- ZOJ 3435 Ideal Puzzle Bobble (莫比乌斯反演基础题)
- 【面试题之算法部分】深入快速排序
- 最简单的HTML5游戏——贪吃蛇
- linux bash总结(二) 高级部分(适合初学者学习和非初学者参考)
- IOS7导航条与状态栏的那些事儿
- Java实现堆
- CocoaPods安装和使用及问题:Setting up CocoaPods master repo