233 Matrix

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 749    Accepted Submission(s): 453

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).
 
Output
For each case, output an,m mod 10000007.
 
Sample Input
1 1
1
2 2
0 0
3 7
23 47 16
 
Sample Output
234
2799
72937
Hint

思路:

第一列元素为:

0

a1

a2

a3

a4

转化为:

23

a1

a2

a3

a4

3

则第二列为:

23*10+3

23*10+3+a1

23*10+3+a1+a2

23*10+3+a1+a2+a3

23*10+3+a1+a2+a3+a4

3

依据前后两列的递推关系,有等式可得矩阵A的元素为:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTcyMTQ0MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

#include"iostream"
#include"stdio.h"
#include"string.h"
#include"algorithm"
#include"queue"
#include"vector"
using namespace std;
#define N 15
#define LL __int64
const int mod=10000007;
int n;
int b[N];
struct Mat
{
LL mat[N][N];
}a,ans;
Mat operator*(Mat a,Mat b)
{
int i,j,k;
Mat c;
memset(c.mat,0,sizeof(c.mat));
for(i=0; i<=n+1; i++)
{
for(j=0; j<=n+1; j++)
{
c.mat[i][j]=0;
for(k=0; k<=n+1; k++)
{
if(a.mat[i][k]&&b.mat[k][j])
{
c.mat[i][j]+=a.mat[i][k]*b.mat[k][j];
c.mat[i][j]%=mod;
}
}
}
}
return c;
}
void mult(int k)
{
int i;
memset(ans.mat,0,sizeof(ans.mat));
for(i=0;i<=n+1;i++)
ans.mat[i][i]=1;
while(k)
{
if(k&1)
ans=ans*a;
k>>=1;
a=a*a;
}
}
void inti()
{
int i,j;
b[0]=23;
b[n+1]=3;
for(i=1; i<=n; i++)
scanf("%d",&b[i]);
memset(a.mat,0,sizeof(a.mat));
for(i=0; i<=n; i++)
{
a.mat[i][0]=10;
a.mat[i][n+1]=1;
}
a.mat[n+1][n+1]=1;
for(i=1; i<n+1; i++)
{
for(j=1; j<=i; j++)
{
a.mat[i][j]=1;
}
}
}
int main()
{
int i,m;
while(scanf("%d%d",&n,&m)!=-1)
{
inti();
mult(m);
LL s=0;
for(i=0;i<=n+1;i++)
s=(s+(ans.mat[n][i]*b[i])%mod)%mod;
printf("%I64d\n",s);
}
return 0;
}

hdu 5015 233 Matrix (矩阵高速幂)的更多相关文章

  1. HDU - 5015 233 Matrix (矩阵快速幂)

    In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...

  2. HDU 5015 233 Matrix --矩阵快速幂

    题意:给出矩阵的第0行(233,2333,23333,...)和第0列a1,a2,...an(n<=10,m<=10^9),给出式子: A[i][j] = A[i-1][j] + A[i] ...

  3. HDU5015 233 Matrix(矩阵高速幂)

    HDU5015 233 Matrix(矩阵高速幂) 题目链接 题目大意: 给出n∗m矩阵,给出第一行a01, a02, a03 ...a0m (各自是233, 2333, 23333...), 再给定 ...

  4. HDU 2254 奥运(矩阵高速幂+二分等比序列求和)

    HDU 2254 奥运(矩阵高速幂+二分等比序列求和) ACM 题目地址:HDU 2254 奥运 题意:  中问题不解释. 分析:  依据floyd的算法,矩阵的k次方表示这个矩阵走了k步.  所以k ...

  5. HDU 1575 Tr A(矩阵高速幂)

    题目地址:HDU 1575 矩阵高速幂裸题. 初学矩阵高速幂.曾经学过高速幂.今天一看矩阵高速幂,原来其原理是一样的,这就好办多了.都是利用二分的思想不断的乘.仅仅只是把数字变成了矩阵而已. 代码例如 ...

  6. HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂

    先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html http://www.cppblog.com/acronix/archive/20 ...

  7. HDU - 5015 233 Matrix(杨辉三角/前缀+矩阵快速幂)

    233 Matrix In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23 ...

  8. 233 Matrix 矩阵快速幂

    In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...

  9. 233 Matrix(矩阵快速幂+思维)

    In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...

随机推荐

  1. raw cannot be resolved or is not a field解决办法

    解决raw文件夹问题 查看左侧项目/res文件夹下是否有raw文件夹,(一定是放到res文件夹下,raw在项目开始创建时候不会自动创建,所以要自己创建)

  2. 程序员段子:世界上最大的同性交友平台github

    程序员(又名程序猿)因为总是冲锋在网络的最前端,还有程序猿的各种特殊性,大家在茶余饭后都有很多关于程序员的段子流传.大多都是程序员自黑的,先说在前面,程序猿还是很好的!下面看看你有没有中枪的那一条呢? ...

  3. Divide and Conquer_1.最大连续子数组

    给定一个数组,求它的一个子数组,使其求和最大. 这个问题的应用:给定一只股票很多天的价格,计算从哪天买进哪天卖出能获得最大利润. 给定 prices:100   113   98   87   65  ...

  4. h5 移动端 监听软键盘弹起、收起

    前面一篇博客 h5 安卓 键盘弹起界面适配 修改webview高度提到了在adnroid中如何监听软键盘的弹起与收起,是利用的窗口的高度发生变化window.onresize事件来做突破点的,但是io ...

  5. cf536d——优先队列的运用

    题目 题目:Lunar New Year and a Wander 题目大意:给定一个n个顶点(编号1~n).m条边的图,求从顶点1出发的字典序最小的路径(途径的边可重复). 思路 使用一个优先队列就 ...

  6. Conv1D和Conv2D的区别

    我的答案是,在Conv2D输入通道为1的情况下,二者是没有区别或者说是可以相互转化的.首先,二者调用的最后的代码都是后端代码(以TensorFlow为例,在tensorflow_backend.py里 ...

  7. configparser logging

    configparser模块 # 该模块适用于配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键=值). import configpar ...

  8. (转载)O(N)的素数筛选法和欧拉函数

    转自:http://blog.csdn.net/dream_you_to_life/article/details/43883367 作者:Sky丶Memory 1.一个数是否为质数的判定. 质数,只 ...

  9. Linux学习笔记01

    1.Linux不靠扩展名区分文件类型2.存储设备必须先挂载才能使用3.Windows下的程序不能直接在Linux中安装和运行 一.服务器的管理预配置Linux的目录的作用:/bin/存放系统命令的目录 ...

  10. xtu summer individual 5 E - Burning Bridges

    Burning Bridges Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...