hdu 5015 233 Matrix(西安网络赛 1009)
来源:互联网 发布:排油减肥产品知乎 编辑:程序博客网 时间:2024/06/04 01:31
233 Matrix
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 670 Accepted Submission(s): 401
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
构造矩阵b:
b[0]=233
b[1]=a[1]
b[2]=a[2]
b[3]=a[3]
......
b[n+1]=3
例如 样例3
b[0]=233
b[1]=23
b[2]=47
b[3]=16
b[4]=3
递推矩阵A,样例3
10 0 0 0 1
1 1 0 0 0
1 1 1 0 0
1 1 1 1 0
0 0 0 0 1
n+2阶方阵
A^m*b的第n项就是结果
代码:
//1046ms#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int mod=10000007;struct matrix{ long long ma[13][13];}a;int n,m;long long b[13];matrix multi(matrix x,matrix y)//矩阵相乘{ matrix ans; memset(ans.ma,0,sizeof(ans.ma)); for(int i=0;i<=n+1;i++) { for(int j=0;j<=n+1;j++) { for(int k=0;k<=n+1;k++) { ans.ma[i][j]=(ans.ma[i][j]+x.ma[i][k]*y.ma[k][j])%mod; } } } return ans;}int main(){ while(~scanf("%d%d",&n,&m)) { memset(a.ma,0,sizeof(a.ma)); b[0]=233; for(int i=1;i<=n;i++) { scanf("%I64d",&b[i]); } b[n+1]=3; a.ma[0][0]=10;//构造a矩阵 a.ma[0][n+1]=1; a.ma[n+1][n+1]=1; for(int i=1;i<=n;i++) { for(int j=0;j<=i;j++) { a.ma[i][j]=1; } } matrix ans; memset(ans.ma,0,sizeof(ans.ma)); for(int i=0;i<=n+1;i++)//单位矩阵 { for(int j=0;j<=n+1;j++) { if(i==j) ans.ma[i][j]=1; } } while(m)//矩阵快速幂 { if(m&1) { ans=multi(ans,a); } a=multi(a,a); m=(m>>1); } matrix mp; memset(mp.ma,0,sizeof(mp.ma)); for(int i=0;i<=n+1;i++)//a的m次方与b矩阵相乘 { for(int k=0;k<=n+1;k++) { mp.ma[i][0]=(mp.ma[i][0]+ans.ma[i][k]*b[k])%mod; } } printf("%I64d\n",mp.ma[n][0]); } return 0;}
0 0
- hdu 5015 233 Matrix(西安网络赛 1009)
- HDU 5015 233 Matrix(西安网络赛I题)
- hdu 5015 233 Matrix(西安网络赛1009)【构造矩阵】
- HDU 5015 233 Matrix(西安网络赛I题, 构造矩阵)
- hdu 5015 233 Matrix 2014年西安网络赛I题
- HDU 5015 233 Matrix(网络赛1009)
- hdu5015 233 Matrix 西安网络赛I题 构造矩阵
- HDU 5015 矩阵优化 (2014西安网络赛)
- HDU 5007 Post Robot(西安网络赛A题)
- HDU 5009 Paint Pearls(西安网络赛C题)
- HDU 5011 Game(西安网络赛E题)
- HDU 5014 Number Sequence(西安网络赛H题)
- HDU 5012 Dice(西安网络赛F题)
- HDU 5017 Ellipsoid(西安网络赛K题)
- hdu 5011 Game(2014 西安网络赛)
- hdu 5014 Number Sequence(西安网络赛1008)
- hdu 5017 Ellipsoid(西安网络赛 1011)
- hdu5015(2014西安网赛) 233 Matrix
- 用户界面线程AfxBeginThread的使用
- 解决NDK开发中Eclipse报错“Unresolved inclusion jni.h”的最终方法
- 硬币找零
- 设计模式六大原则(6):开闭原则
- 流量统计原理,sliding抽屉的使用
- hdu 5015 233 Matrix(西安网络赛 1009)
- 修改Extjs默认字体
- 安装和使用cocoaPods
- UVa11427 Expect the Expected
- 一个完整推荐系统的设计实现-以百度关键词搜索推荐为例
- Java之enum
- 集合类
- erlang后台存储选择
- path与classpath的区别