hdu 5015 233 Matrix (矩阵高速幂)
233 Matrix
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 749 Accepted Submission(s): 453
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?
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).
1 1
1
2 2
0 0
3 7
23 47 16
234
2799
72937Hint![]()
思路:
第一列元素为:
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 (矩阵高速幂)的更多相关文章
- HDU - 5015 233 Matrix (矩阵快速幂)
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
- 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] ...
- HDU5015 233 Matrix(矩阵高速幂)
HDU5015 233 Matrix(矩阵高速幂) 题目链接 题目大意: 给出n∗m矩阵,给出第一行a01, a02, a03 ...a0m (各自是233, 2333, 23333...), 再给定 ...
- HDU 2254 奥运(矩阵高速幂+二分等比序列求和)
HDU 2254 奥运(矩阵高速幂+二分等比序列求和) ACM 题目地址:HDU 2254 奥运 题意: 中问题不解释. 分析: 依据floyd的算法,矩阵的k次方表示这个矩阵走了k步. 所以k ...
- HDU 1575 Tr A(矩阵高速幂)
题目地址:HDU 1575 矩阵高速幂裸题. 初学矩阵高速幂.曾经学过高速幂.今天一看矩阵高速幂,原来其原理是一样的,这就好办多了.都是利用二分的思想不断的乘.仅仅只是把数字变成了矩阵而已. 代码例如 ...
- HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂
先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html http://www.cppblog.com/acronix/archive/20 ...
- HDU - 5015 233 Matrix(杨辉三角/前缀+矩阵快速幂)
233 Matrix In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23 ...
- 233 Matrix 矩阵快速幂
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
- 233 Matrix(矩阵快速幂+思维)
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
随机推荐
- 【译】x86程序员手册39-10.3切换到保护模式
10.3 Switching to Protected Mode 切换到保护模式 Setting the PE bit of the MSW in CR0 causes the 80386 to b ...
- python学习日记-01
一. 熟悉 在正式介绍python之前,了解下面两个基本操作对后面的学习是有好处的: (1)基本的输入输出 可以在Python中使用+.-.*./直接进行四则运算. >>> 1+3* ...
- windows ubuntu bcdeditor
双系统. 先装windows,后装ubuntu12.04 为了避免grub引导,所以安装bcdeditor. 平时使用没有什么不适,可是每次linux升级内核以后,grub列表可能就会消失,自然是不能 ...
- day21-3 类的组合
目录 类的组合 组合的应用 类的组合 组合就是一个类的对象具备某一个属性,该属性的值是指向另外一个类的对象 组合的好处:解决类与类之间代码冗余的问题 组合的应用 需求:假如我们需要给学生增添课程属性, ...
- 17Web服务器端控件
Web服务器端控件 Web服务器端控件 ASP.Net提供了两类服务器端控件:Html服务器端控件和Web服务器端控件.由于Web服务器端控件功能更强大,和Windows应用程序的控件使用方法类似,容 ...
- filezilla server FTP 安装报错 "could not load TLS network. Aborting start of administration interface"
filezilla server FTP 安装报错 "could not load TLS network. Aborting start of administration inter ...
- 浅谈FFT(快速博立叶变换)&学习笔记
0XFF---FFT是啥? FFT是一种DFT的高效算法,称为快速傅立叶变换(fast Fourier transform),它根据离散傅氏变换的奇.偶.虚.实等 特性,对离散傅立叶变换的算法进行改进 ...
- Go:面向"对象"
一.封装 封装的实现步骤: 将结构体.字段的首字母小写(不能被导出): 给结构体所在的包提供一个工厂模式的函数,首字母大写.类似一个构造函数: 提供一个首字母大写的方法,由于获取结构体属性的值. 二. ...
- centos 简单用户管理
一.配置文件 /etc/passwd:存放用户信息,以“:”分割成7个部分 1.账号名称,用来对应UID: 2.早期密码存放位置,后来密码改存/etc/shadow中,以“x”代替: 3.UID,使用 ...
- linux下硬盘分区、格式化以及文件管理系统
1.添加虚拟硬盘 (1)点击编辑虚拟机位置,然后点击添加 (2)点击添加硬盘 (3)点击下一步 (4)创建新虚拟磁盘并点击下一步 (5)指定磁盘容量并且点击下一步 (6)点击完成 2.系统分区 当 ...