233 Matrix

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 a 0,1 = 233,a 0,2 = 2333,a 0,3 = 23333...) Besides, in 233 matrix, we got ai,j = a i-1,j +a i,j-1( i,j ≠ 0). Now you have known a 1,0,a 2,0,...,a n,0, could you tell me a n,m in the 233 matrix?

InputThere are multiple test cases. Please process till EOF.

For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 10 9). The second line contains n integers, a 1,0,a 2,0,...,a n,0(0 ≤ a i,0 < 2 31).OutputFor each case, output a n,m mod 10000007.Sample Input

1 1
1
2 2
0 0
3 7
23 47 16

Sample Output

234
2799
72937

Hint

#include<bits/stdc++.h>
#define MAX 15
#define MOD 10000007
using namespace std;
typedef long long ll; ll n,m;
struct mat{
ll a[MAX][MAX];
}; mat operator *(mat x,mat y)
{
mat ans;
memset(ans.a,,sizeof(ans.a));
for(int i=;i<=n+;i++){
for(int j=;j<=n+;j++){
for(int k=;k<=n+;k++){
ans.a[i][j]+=x.a[i][k]*y.a[k][j]%MOD;
ans.a[i][j]%=MOD;
}
}
}
return ans;
}
mat qMod(mat a,ll nn)
{
mat t;
memset(t.a,,sizeof(t.a));
for(int i=;i<=n+;i++){
t.a[i][]=;
for(int j=;j<=i;j++){
t.a[i][j]=;
}
t.a[i][n+]=;
}
t.a[n+][n+]=;
while(nn){
if(nn&) a=t*a;
nn>>=;
t=t*t;
}
return a;
}
int main()
{
int t,i,j;
while(~scanf("%I64d%I64d",&n,&m)){
mat a;
memset(a.a,,sizeof(a.a));
a.a[][]=;
for(i=;i<=n+;i++){
scanf("%I64d",&a.a[i][]);
}
a.a[n+][]=;
a=qMod(a,m);
printf("%I64d\n",a.a[n+][]);
}
return ;
}

HDU - 5015 233 Matrix(杨辉三角/前缀+矩阵快速幂)的更多相关文章

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

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

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

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

  3. HDU 5434 Peace small elephant 状压dp+矩阵快速幂

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant  Accepts: 38  Submissions: ...

  4. HDU 5318——The Goddess Of The Moon——————【矩阵快速幂】

    The Goddess Of The Moon Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  5. POJ 3233 Matrix Power Series 【经典矩阵快速幂+二分】

    任意门:http://poj.org/problem?id=3233 Matrix Power Series Time Limit: 3000MS   Memory Limit: 131072K To ...

  6. hdu 4549 M斐波拉契 (矩阵快速幂 + 费马小定理)

    Problem DescriptionM斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = aF[1] = bF[n] = F[n-1] * F[n-2] ( n > 1 ) 现在 ...

  7. HDU 5015 233 Matrix

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

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

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

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

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

随机推荐

  1. svn服务器 vim 修改 authz passwd 添加用户

    进入svn服务器 vim 修改 authz passwd 添加用户 SVN服务器之------2,配置PhpStorm连接SVN服务器(其他IDE大同小异) - 学到老死 - 博客园 https:// ...

  2. update module (更新模块)

    [转自http://blog.csdn.net/zhongguomao/article/details/6712568] function module:更新程序必须用一个特殊的FM(update m ...

  3. Git如何强制拉取一个远程分支到本地分支(转载)

    有时候,我们在使用git pull指令想把一个远程分支拉取到本地分支的时候,老是会拉取失败,这一般是因为某种原因,本地分支和远程分支的内容差异无法被git成功识别出来,所以git pull指令什么都不 ...

  4. ansible3

    一.setup模块 ansible的setup模块主要用来收集信息,查看参数: [root@localhost ~]# ansible-doc -s setup # 查看参数,部分参数如下: filt ...

  5. 常见的CSS命名

    1:header(头部)logo  topbar lang search topmenu banner nav headbox active(活动的) selectselectTop selectLi ...

  6. 9.2 NOIP提高组试题精解(2)

    9-18 fruit.c #include <stdio.h> #define MAXN 10000 int Queue1[MAXN], Queue2[MAXN]; void Insert ...

  7. UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)

    py文件直接在cmd窗口用python命令执行时正常:代码逐句在ipython中也正常:但是, 在wingIDE中运行报错“UnicodeEncodeError: 'ascii' codec can' ...

  8. 《java编程思想》:第五章,初始化与清理

    知识点整理: 1.从概念上讲,‘初始化’与‘创建’是彼此独立的,但是在Java中,两者被捆绑在一起,不可分离. 2.区分重载的方法:每个重载的方法都有一个独一无二的参数类型列表. 甚至参数顺序的不同也 ...

  9. linux命令学习笔记(32):gzip命令

    减少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时,可以减少传输的时间. gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令,既方便又好用.gzip不仅可以 ...

  10. 【QT】《转载》常用快捷键

    F1        查看帮助F2        跳转到函数定义(和Ctrl+鼠标左键一样的效果)Shift+F2    声明和定义之间切换F4        头文件和源文件之间切换Ctrl+1     ...