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. Android嵌入式安卓触摸屏|4418开发板平台

    核心板参数 尺寸:50mm*60mm 高度:核心板连接器为1.5mm 4418 CPU:ARM Cortex-A9 四核 S5P4418处理器 1.4GHz 6818 CPU:ARM Cortex-A ...

  2. (转)淘淘商城系列——引用dubbo服务

    http://blog.csdn.net/yerenyuan_pku/article/details/72758663 上文我们一起学习了如何发布一个dubbo服务,本文我就来教大家如何在web工程中 ...

  3. 框架开发之Java注解的妙用

    注解的好处:1.能够读懂别人写的代码,特别是框架相关的代码.2.本来可能需要很多配置文件,需要很多逻辑才能实现的内容,就可以使用一个或者多个注解来替代,这样就使得编程更加简洁,代码更加清晰.3.(重点 ...

  4. laravel UserRequest $request error

    laravel UserRequest $request error Ask Question   0   laravel5.2,I create a UserRequest.php under Re ...

  5. CREATE VIEW - 定义一个视图

    SYNOPSIS CREATE [ OR REPLACE ] VIEW name [ ( column_name [, ...] ) ] AS query DESCRIPTION 描述 CREATE ...

  6. cookie和session的用法用途,执行流程,区别联系

    1.为什么要有cookie/session?在客户端浏览器向服务器发送请求,服务器做出响应之后,二者便会断开连接(一次会话结束).那么下次用户再来请求服务器,服务器没有任何办法去识别此用户是谁.比如w ...

  7. Domain Adaptation论文笔记

    领域自适应问题一般有两个域,一个是源域,一个是目标域,领域自适应可利用来自源域的带标签的数据(源域中有大量带标签的数据)来帮助学习目标域中的网络参数(目标域中很少甚至没有带标签的数据).领域自适应如今 ...

  8. Eclipse使用入门指南及技巧

    Java是必须的   安装一个JDK就可以了,比如jdk-6u39-windows-x64.exe,安装完毕,会自行安装JRE. 如果不用IDE,这个时候用记事本也是可以写程序,然后用javac编译, ...

  9. ubuntu 普通用户运行virt-manager时libvirt权限设置

    error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission deniederror: failed t ...

  10. idea关闭,tomcat却没关闭的设置方法

    最近,遇到个事,我在打开tomcat时,关闭了idea,再次打开时,运行tomcat时,发现端口占用,查看任务管理器,发现,tomcat没有随idea的关闭而关闭. 后来,想想,可能是,在关闭时,点了 ...