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 ;
}

最新文章

  1. UITableview中怎么找到每个cell
  2. Python的hasattr() getattr() setattr() 函数使用方法详解
  3. 如何从github上面拷贝源码
  4. android 获取路径目录方法以及判断目录是否存在,创建目录
  5. WPF 之 利用Visibility属性进行Item模板切换
  6. emoji表情符处理替换成空格
  7. 经验分享:CSS浮动(float,clear)通俗讲解 太棒了,清晰明了
  8. Android 实现左右滑动效果ViewFlipper终结【转】
  9. 【转】C++ stringstream介绍,使用方法与例子
  10. sql语法复习:增删查改,各种数据库对象创建和函数使用
  11. c语言第五次作业0
  12. MQTT入手笔记(二)
  13. Ansible-Zabbix-基础agent批量装机
  14. JMeter 接口测试(一)
  15. 第 9 章 数据管理 - 077 - 跨主机使用 Rex-Ray volume
  16. 第十二章 FTP服务器安装与配置
  17. 怎么下载geventwebsocket
  18. manjaro使用国内软件源
  19. DAY6 元组、字典与集合
  20. Outlook错误代码

热门文章

  1. java网络编程UDP
  2. Word中公式和文字混排对齐的问题
  3. JavaScript--输出内容(document.write)
  4. mysql中类型转换
  5. ACM_无聊者序列(斐波那契数列大数取余(同余)+规律)
  6. hbuilder中的 http://www.w3.org/TR/html4/frameset.dtd
  7. action=&quot;post&quot; 、 servletconfig 、 servletcontext 、getPrintWiter() 、context-param、 init-param(第一个完整的servlet)
  8. [转]Android自定义Adapter的ListView的思路及代码
  9. EasyUI系列学习(四)-Droppable(放置)
  10. Laravel 5.4.36 session 生效问题