HDU - 5015 233 Matrix(杨辉三角/前缀+矩阵快速幂)
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(杨辉三角/前缀+矩阵快速幂)的更多相关文章
- HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂
先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html http://www.cppblog.com/acronix/archive/20 ...
- HDU - 5015 233 Matrix (矩阵快速幂)
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
- HDU 5434 Peace small elephant 状压dp+矩阵快速幂
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant Accepts: 38 Submissions: ...
- 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/ ...
- POJ 3233 Matrix Power Series 【经典矩阵快速幂+二分】
任意门:http://poj.org/problem?id=3233 Matrix Power Series Time Limit: 3000MS Memory Limit: 131072K To ...
- hdu 4549 M斐波拉契 (矩阵快速幂 + 费马小定理)
Problem DescriptionM斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = aF[1] = bF[n] = F[n-1] * F[n-2] ( n > 1 ) 现在 ...
- HDU 5015 233 Matrix
题意:给定一个矩阵的第0列的第1到n个数,第一行第1个数开始每个数分别为233, 2333........,求第n行的第m个数. 分析: 其实也没那么难,自己想了半天还没往对的方向想,m最大1e9,应 ...
- hdu 5015 233 Matrix (矩阵高速幂)
233 Matrix Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
- hdu 5015 233 Matrix(构造矩阵)
http://acm.hdu.edu.cn/showproblem.php?pid=5015 由于是个二维的递推式,当时没有想到能够这样构造矩阵.从列上看,当前这一列都是由前一列递推得到.依据这一点来 ...
随机推荐
- MongoDB的对象的创建
package com.voice.db; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.Mon ...
- 九度OJ 1054:字符串内排序 (排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:7949 解决:4343 题目描述: 输入一个字符串,长度小于等于200,然后将输出按字符顺序升序排序后的字符串. 输入: 测试数据有多组,输 ...
- linux c编程:文件的读写
Linux系统中提供了系统调用函数open()和close()用于打开和关闭一个存在的文件 int open(const char *pathname,int flags) int open(cons ...
- imagecopyresampled()改变图片大小后质量要比imagecopyresized()高。
php程序中改变图片大小的函数大多数人都想到用imagecopyresized(),不过经过测试比较发现,使用imagecopyresampled()改变的图片质量更高. 下面我们来看看两者的比较结果 ...
- Bootstrap——组件
1.字体图标 <span class="glyphicon glyphicon-star" aria-hidden="true"></span ...
- eslint 配合 git (husky)
为了保证每次提交的 git 代码是正确的,为此我们可以使用 eslint 配合 git hook, 在进行git commit 的时候验证eslint规范 如果 eslint 验证不通过,则不能提交. ...
- matplotlib和numpy 学习笔记
1. 在二维坐标系中画一个曲线 import matplotlib.pyplot as plt #data len=400, store int value data = [] #set x,y轴坐标 ...
- java.lang.UnsupportedClassVersionError: com/dw/Function : Unsupported major.minor version 52.0
本地环境中有jdk7和jdk8,当把jdk8改为jdk7时,出现如下错误,是jdk版本的问题,在Properties-->JAVA Compiler-中的Compiler compliance ...
- 3D焦点图插件
在线演示 本地下载
- ES搜索排序,文档相关度评分介绍——Vector Space Model
Vector Space Model The vector space model provides a way of comparing a multiterm query against a do ...