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 a i,j = a i-1,j +a i,j-1( i,j ≠ 0). Now you have known a 1,0,a2,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 ≤ 109). 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
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 18
#define N 33
#define MOD 10000007
#define INF 1000000009
const double eps = 1e-;
const double PI = acos(-1.0);
/*
组合数学 找规律
递归显然不行,列数太多
只需考虑每个点被加上的次数
a(i,0) = a(i,1) 到 a(n,m) 路径条数(向左和向下两个方向) C(n+m-i-1,n)
发现列数太多没办法打表 再换一种方法
矩阵快速幂
从第一列向后考虑 找出他们的转移矩阵(这里很巧妙的加了一条边 凑2333后面的3)十分巧妙!~
*/
LL a[MAXN], n, m;
struct mat
{
LL data[MAXN][MAXN];
mat()
{
memset(data, , sizeof(data));
}
mat operator*(const mat& rhs)
{
mat ret;
for (int i = ; i <= n + ; i++)
{
for (int j = ; j <= n + ; j++)
{
for (int k = ; k <= n + ; k++)
ret.data[i][j] = (ret.data[i][j] + data[i][k] * rhs.data[k][j]) % MOD;
}
}
return ret;
}
};
mat fpow(mat a, LL b)
{
if (b <= ) return a;
mat tmp = a, ret;
for (int i = ; i <= n + ; i++)
ret.data[i][i] = ;
while (b!= )
{
if (b & )
ret = tmp*ret;
tmp = tmp*tmp;
b = b / ;
}
return ret;
}
int main()
{
while (cin >> n >> m)
{
a[] = ;
for (int i = ; i <= n + ; i++)
cin >> a[i];
a[n + ] = ;
mat ans;
for (int i = ; i <= n + ; i++)
{
ans.data[i][] = ;
ans.data[i][n + ] = ;
for (int j = ; j <= i; j++)
ans.data[i][j] = ;
}
ans.data[n + ][n + ] = ;
ans = fpow(ans, m);
LL result = ;
for (int i = ; i <= n + ; i++)
result = (result + a[i] * ans.data[n + ][i]) % MOD;
cout << result << endl;
}
return ;
}

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. 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. PCB genesis加尾孔实现方法

    一.为什么增加尾孔呢 看一看下图在panel中增加尾孔的效果;如下图所示,主要有2点原因. 1.孔径大小测量 假设如果不增加尾孔,要检测孔径大小是否符合要求,那么QA检测会选择最后钻的孔进大小进行测量 ...

  2. PCB 规则引擎之JSON对象查看器

    在PCB规则引擎开发中,JavaScript V8引擎是处理业务逻辑的, 当然业务逻辑需要数据支撑才行,  即需有将数据推进入到V8引擎.目前这边数据传输到JavaScript V8引擎以C# Mod ...

  3. P3199 [HNOI2009]最小圈

    传送门 据rqy说有这么一个结论\[ans=\min_{v \in V,F_n(v)\neq \infty} \max_{0 \leq k \leq n - 1} \left[\frac{F_n(v) ...

  4. iview日期选择框,获取的日期总是少一天

    使用iview的datepicker时间选择器发现获取的value值是比实际要少一天,严格来说应该是时间格式不一样,datepicker获取的时间是UTC时间 格式,也就是:yyyy-MM-ddTHH ...

  5. github fork项目更改后与原作者同步更新

    1.进入你的GitHub发起Pull request 2.选择compare across forks 3.反向操作.base fork改为自己的,head fork改为原作者的 4.点击 creat ...

  6. CentOS 7.0 firewall防火墙关闭firewall作为防火墙,这里改为iptables防火墙

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤: 1.先检查是否安装了: iptables service iptables status 2.安装ip ...

  7. 51nod 1222 莫比乌斯反演

    思路: yhx找的反演题 题解已经烂大街了 #pragma GCC optimize("O3") //By SiriusRen #include <bits/stdc++.h ...

  8. photoshop制作古风画

    效果图: 素材结构: 前期准备: 素材准备,我的素材包括:印章.花束.二次元妹纸,背景图片. 软件准备,用的软件是 photoshop CS6. 把二次元妹纸拖入photoshop,把她抠出来,Ctr ...

  9. spring 将配置文件中的值注入 属性

    1.编写配置文件 #债权转让 #默认周期 必须大于0 credit.defaultDuration=1 #最小转让金额(元) credit.minBidAmount=1.00 #最小转让时间 到期时间 ...

  10. 在oninitdialog后添加初始化变量

    需要 UpdateData(FALSE); 刷新界面 不然有时会不显示.