非常显然矩阵的第一列为:

0

a[1]

a[2]

a[3]

a[4]

我们转化一下,转化为

23

a[1]

a[2]

a[3]

a[4]

3

那么由第一列转移到第二列则为

23*10+3

a[1]+23*10+3

a[2]+a[1]+23*10+3

a[3]+a[2]+a[1]+23*10+3

a[4]+a[3]+a[2]+a[1]+23*10+3

3

非常显然转移矩阵A就出来了:

10 0 0 0 0 1

10 1 0 0 0 1

10 1 1 0 0 1

10 1 1 1 0 1

10 1 1 1 1 1

0  0 0 0 0 1

那么最后一列就是A的m次方*第一列。

#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define maxn 110000
#define mod 10000007
#define LL __int64
struct matrix
{
LL mat[15][15];
matrix()
{
memset(mat,0,sizeof(mat));
}
};
int a[11];
int n;
matrix mul(matrix A,matrix B)
{
matrix C;
int i,j,k;
for(i=1; i<=n+2; i++)
{
for(j=1; j<=n+2; j++)
{
for(k=1; k<=n+2; k++)
{
C.mat[i][j]=(C.mat[i][j]+A.mat[i][k]*B.mat[k][j])%mod;
}
}
}
return C;
}
matrix powmul(matrix A,int k)
{
matrix B;
for(int i=1;i<=n+2;i++)B.mat[i][i]=1;
while(k>=1)
{
if(k&1)B=mul(B,A);
A=mul(A,A);
k=k/2;
}
return B;
}
void print(matrix A)
{
cout<<"matrix A"<<endl;
for(int i=1;i<=n+2;i++)
{
for(int j=1;j<=n+2;j++)
{
cout<<A.mat[i][j]<<" ";
}
cout<<endl;
}
}
int main()
{
int m;
while(~scanf("%d%d",&n,&m))
{
matrix A,B;
A.mat[1][1]=23;
for(int i=1;i<=n;i++)
{
scanf("%d",&A.mat[i+1][1]);
}
A.mat[n+2][1]=3;
for(int i=1;i<=n+1;i++)B.mat[i][1]=10;
for(int i=1;i<=n+2;i++)B.mat[i][n+2]=1;
for(int i=2;i<=n+1;i++)
{
for(int j=2;j<=i;j++)B.mat[i][j]=1;
}
// print(A);
// print(B);
B=powmul(B,m);
A=mul(B,A);
// print(A);
cout<<A.mat[n+1][1]<<endl;
}
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. HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂

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

  4. hdu 5015 233 Matrix (矩阵高速幂)

    233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tota ...

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

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

  6. hdu 5015 233 Matrix(构造矩阵)

    http://acm.hdu.edu.cn/showproblem.php?pid=5015 由于是个二维的递推式,当时没有想到能够这样构造矩阵.从列上看,当前这一列都是由前一列递推得到.依据这一点来 ...

  7. HDU 5015 233 Matrix

    题意:给定一个矩阵的第0列的第1到n个数,第一行第1个数开始每个数分别为233, 2333........,求第n行的第m个数. 分析: 其实也没那么难,自己想了半天还没往对的方向想,m最大1e9,应 ...

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

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

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

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

  10. HDU5015 233 Matrix —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-5015 233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memor ...

随机推荐

  1. 大素数判断和素因子分解(miller-rabin,Pollard_rho算法)

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

  2. [HEOI2016/TJOI2016][bzoj4555] 求和 [斯特林数+NTT]

    题面 传送门 思路 首先,我们发现这个式子中大部分的项都和$j$有关(尤其是后面的$2^j\ast j!$),所以我们更换一下枚举方式,把这道题的枚举方式变成先$j$再$i$ $f(n)=\sum_{ ...

  3. react history模式下的白屏问题

    近期,再用react的时候,由于不想用丑陋的hash,便将路由模式切换成history了,结果带来了一些问题,比如刷新白屏,还有图片加载不出来,这里我们说一下解决方案. 原因 首先,我们说一下造成这一 ...

  4. js, lambada? 在chrome和node下可以使用

    var a=function(a,c){if(a)c(a)} undefined a(true,(console.log)) VM177:2 Uncaught TypeError: Illegal i ...

  5. 使用vim修改和查看16进制文件

    使用前的准备工作,如果没有安装,使用命令安装: pacman -S vim 使用vim的十六进制功能查看和编辑文本文件,创建测试文件,使用命令如下: vim test.txt 进入“插入”模式,使用命 ...

  6. Android新特性之CardView的简单使用

    Android新特性之CardView的简单使用 我们学习下Android5.0的新增加的控件CardView.首先我们了解一下CardView的基本使用,然后结合RecycleView使用CardV ...

  7. Codeforces 586D Phillip and Trains(DP)

    题目链接 Phillip and Trains 考虑相对位移. 每一轮人向右移动一格,再在竖直方向上移动0~1格,列车再向左移动两格. 这个过程相当于每一轮人向右移动一格,再在竖直方向上移动0~1格, ...

  8. meta 标签大全

    相信在html5之前,很少人会关注html页面上head里标签元素的定义和应用场景,可能记得住的只有"title"."keyword"和"descri ...

  9. linux基础学习6

    daemon 可以理解成为service   两大类: stand_alone:此 daemon 可以自行单独启动服务,加载到内存后就一直占用内存与系统资源:如 www的httpd ,ftp的vsft ...

  10. IOS 暂停和恢复CALayer上的动画(转)

    coreAnimation的动画是存在于CALayer上面的,有些时候需要突然暂停某个组件的动画效果,同时保留当前动画的状态, 如果是用removeAnimation会显得很突兀,不够平滑,所以可以利 ...