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. [SoapUI] 在Test Step 下加Script Assertion,用 messageExchange 获取当前步骤的response content

    //Get response content of the current request def response = messageExchange.getResponseContent() // ...

  2. UEFI下win10+Ubuntu双启动后完全纯净卸载Ubuntu,重建BCD

    以下内容操作具有风险,操作前请提前备份数据.建议由有丰富经验的人使用,需要掌握diskpart. 背景 使用ubuntu+win10 dual boot后,需要重置回纯净win10系统. BCD是Bo ...

  3. CentOS7安装redis,并设置开机自启动

    卸载redis 停止并删除所有已的rendis目录即可. rm -rf /home/wls/soft/redis-4.0.2 rm -rf /etc/redis* rm -rf /var/log/re ...

  4. python学习的一点点心得

    好久没发博客了,不解释....接下来写一点自己最近学习python的一点心得. 想要学习python的初衷,是看<软件测试技术大全>一书时,了解到像perl.python.ruby等脚本类 ...

  5. [GO]方法的重写

    package main import "fmt" type Person struct { name string sex byte age int } func (tmp Pe ...

  6. java TimeZone类

    TimeZone类主要是对时区的操作 下面是一个简单的例子 public static void main(String[] args) { // TODO Auto-generated method ...

  7. KindEditor3.x整合教程-Xproer.WordPaster

    版权所有 2009-2017 荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webplug/wordpa ...

  8. sudo -s/sodo -i/su root

    sudo : 暂时切换到超级用户模式以执行超级用户权限,提示输入密码时该密码为当前用户的密码,而不是超级账户的密码.不过有时间限制,Ubuntu默认为一次时长15分钟.su : 切换到某某用户模式,提 ...

  9. PMBOK项目管理认知概要

    2015年6月,通过努力取得PMP证书,很是欣喜,也是对努力付出的一种奖励吧! 通过学习PMP相关的项目管理的知识,对国外的项目管理技术有更加系统的认知.理解.掌握,熟悉全项目生命周期的管理. 其实对 ...

  10. MAVEN 编译打包时报“找不到符号”cannot find symbol 的处理方法总结

    http://www.cnblogs.com/Starshot/p/7441075.html