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?

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 ≤ 10 9). The second line contains n integers, a 1,0,a 2,0,...,a n,0(0 ≤ a i,0 < 2 31).

Output

For 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

这个题的难点在于如何去构造矩阵,我们一般的构造矩阵是一维递推式,这个我们也可以通过改变一下就我们让第一行为23,最后一行为3,然后根据递推关系判断

如图:

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#include<cmath>
const long long mod=10000007; const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int n,m;
struct mat
{
ll a[15][15];
}; mat Mul(mat a,mat b)
{
mat ans;
memset(ans.a,0,sizeof(ans.a));
for(int t=0;t<=n+1;t++)
{
for(int j=0;j<=n+1;j++)
{
for(int k=0;k<=n+1;k++)
{
ans.a[t][j]=(ans.a[t][j]+a.a[t][k]*b.a[k][j])%mod;
}
}
}
return ans;
}
mat anss;
ll quickPow(int k)
{
mat res;
memset(res.a,0,sizeof(res.a));
for(int t=0;t<=n;t++)
{
res.a[t][0]=10;
}
for(int t=0;t<=n;t++)
{
for(int j=1;j<=t;j++)
{
res.a[t][j]=1;
}
res.a[t][n+1]=1;
}
for(int t=0;t<=n;t++)
{
res.a[n+1][t]=0;
}
res.a[n+1][n+1]=1;
while(k)
{
if(k&1)
{
anss=Mul(res,anss);
}
res=Mul(res,res);
k>>=1;
} return anss.a[n][0]%mod;
} int main()
{ while(cin>>n>>m)
{
memset(anss.a,0,sizeof(anss.a));
anss.a[0][0]=23;
for(int t=1;t<=n;t++)
{
scanf("%lld",&anss.a[t][0]);
}
anss.a[n+1][0]=3;
cout<<quickPow(m)<<endl; }
return 0;
}

233 Matrix(矩阵快速幂+思维)的更多相关文章

  1. 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 (矩阵快速幂)

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

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

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

  4. 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] ...

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

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

  6. fzu 1911 Construct a Matrix(矩阵快速幂+规律)

    题目链接:fzu 1911 Construct a Matrix 题目大意:给出n和m,f[i]为斐波那契数列,s[i]为斐波那契数列前i项的和.r = s[n] % m.构造一个r * r的矩阵,只 ...

  7. UVa 11149 Power of Matrix (矩阵快速幂,倍增法或构造矩阵)

    题意:求A + A^2 + A^3 + ... + A^m. 析:主要是两种方式,第一种是倍增法,把A + A^2 + A^3 + ... + A^m,拆成两部分,一部分是(E + A^(m/2))( ...

  8. UVa 11149 Power of Matrix 矩阵快速幂

    题意: 给出一个\(n \times n\)的矩阵\(A\),求\(A+A^2+A^3+ \cdots + A^k\). 分析: 这题是有\(k=0\)的情况,我们一开始先特判一下,直接输出单位矩阵\ ...

  9. Construct a Matrix (矩阵快速幂+构造)

    There is a set of matrixes that are constructed subject to the following constraints: 1. The matrix ...

随机推荐

  1. 以二进制的形式查看文件 Linux之od命令详解

    od命令 以二进制的形式查看文件 od -t x1 /usr/local/FT/config/hsm_create.utf8.sql ef bb bf 4c 5f 0d 0a 5f 4e 4e 4f ...

  2. Mybatis:动态sql

    动态 SQL MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其他类似框架的经验,你就能体会到根据不同条件拼接 SQL 语句有多么痛苦.拼接的时候要确保不能忘了必要的空格 ...

  3. Swift实现Touch ID验证

    iOS8开放了很多API,包括HomeKit.HealthKit什么的.我们这里要说的是其中之一的Touch ID验证. 以前用app保护用户的隐私内容,只能设定和输入密码.眼看着只能是iPhone本 ...

  4. 编写高质量代码改善C#程序的157个建议——建议100:静态方法和实例方法没有区别

    建议100:静态方法和实例方法没有区别 静态方法在加载时机和内存使用上和实例方法完全一致.在这里,我们先引出一个概念“类型对象”.比如类型Person,我们都知道new Person() 会产生一个对 ...

  5. 编写高质量代码改善C#程序的157个建议——建议69:应使用finally避免资源泄漏

    建议69:应使用finally避免资源泄漏 除非发生让应用程序中断的异常,否则finally总是会先于return执行.finally的这个语言特性决定了资源释放的最佳位置就是在finally块中:另 ...

  6. CentOS 7安装GitLab、汉化、配置邮件发送

    1.更换国内yum源 1.1 备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 1.2 ...

  7. sersync服务搭建

    前言: 一.为什么要用Rsync+sersync架构? 1.sersync是基于Inotify开发的,类似于Inotify-tools的工具 2.sersync可以记录下被监听目录中发生变化的(包括增 ...

  8. day 21 01 序列化模块和模块的导入的复习以及包的初识

    day 21 01 序列化和模块的导入的复习以及包的初识 1.序列化模块 什么是序列化模块:数据类型转化成字符串的过程就是序列卷 为什么要使用序列化模块:为了方便存储和网络传输 三种序列化模块: (1 ...

  9. 等等,你可能误解nodejs了–通俗的概括nodejs的真相

    最近刚把产品从cpp平台迁移到nodejs平台了.  很多以前关于nodejs的观念被颠覆了. 这里分享出来, 欢迎大家批评指正. "nodejs是做服务器端开发的, 它一定和web相关,几 ...

  10. c# 变量交换

    C#  变量交换 变量交换的方法: 1.借助第三个变量: class Program { static void Main(string[] args) { Exchage(,); } /// < ...