233 Matrix(矩阵快速幂+思维)
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(矩阵快速幂+思维)的更多相关文章
- 233 Matrix 矩阵快速幂
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
- HDU - 5015 233 Matrix (矩阵快速幂)
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
- HDU5015 233 Matrix —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-5015 233 Matrix Time Limit: 10000/5000 MS (Java/Others) Memor ...
- 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] ...
- HDU5015 233 Matrix(矩阵高速幂)
HDU5015 233 Matrix(矩阵高速幂) 题目链接 题目大意: 给出n∗m矩阵,给出第一行a01, a02, a03 ...a0m (各自是233, 2333, 23333...), 再给定 ...
- fzu 1911 Construct a Matrix(矩阵快速幂+规律)
题目链接:fzu 1911 Construct a Matrix 题目大意:给出n和m,f[i]为斐波那契数列,s[i]为斐波那契数列前i项的和.r = s[n] % m.构造一个r * r的矩阵,只 ...
- UVa 11149 Power of Matrix (矩阵快速幂,倍增法或构造矩阵)
题意:求A + A^2 + A^3 + ... + A^m. 析:主要是两种方式,第一种是倍增法,把A + A^2 + A^3 + ... + A^m,拆成两部分,一部分是(E + A^(m/2))( ...
- UVa 11149 Power of Matrix 矩阵快速幂
题意: 给出一个\(n \times n\)的矩阵\(A\),求\(A+A^2+A^3+ \cdots + A^k\). 分析: 这题是有\(k=0\)的情况,我们一开始先特判一下,直接输出单位矩阵\ ...
- Construct a Matrix (矩阵快速幂+构造)
There is a set of matrixes that are constructed subject to the following constraints: 1. The matrix ...
随机推荐
- Exception in thread "main" org.springframework.beans.factory.BeanCreationException
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error ...
- ECS 游戏架构 理解
转载自:http://blog.csdn.net/i_dovelemon/article/details/25798677 理解 组件-实体-系统 (ECS \CES)游戏编程模型 - 博客频道 ...
- cs231n(一)
1.Nearest Neighbor Classifier 计算未分类数据(图片)与已标记类别的训练数据(training set)的距离(L1,L2等距离),然后返回与训练数据(图片)最小距离的图片 ...
- Insufficient free space for journal files
前两天请假了,公司的很多app突然挂掉了,说是mongodb莫名的挂掉了,赶紧进去看了看日志: --31T14:: [initandlisten] ERROR: Insufficient free s ...
- debian 9 更换源 使用国内源 配置方法
配置前请先参考: https://wiki.debian.org/SourcesList https://www.debian.org/mirror/list https://mirrors.tuna ...
- Swig在Mac OS X上的安装
网上有很多类似文章介绍Swig怎么在Mac OS X上安装和配置,一般来说就是: 下载pcre,configure & make & make install 下载swig,confi ...
- paperfree
主题:免费的论文查重网站 正文:给大家推荐一个免费的论文查重网站PaperFree:http://www.paperfree.cn
- 安装DotNetCore.1.0.0-VS2015Tools.Preview2一直失败
266C:22B0][2016-08-01T23:02:29]i052: Condition 'WixBundleInstalled OR NOT(NetFx45Release < 378675 ...
- find查找到并删除,替换指定文件
1.删除/root/work/tomcat/logs/目录下,所有目录. find /root/work/tomcat/logs/* -type d | xargs rm -rf 顺便列一下find的 ...
- C# JackLib系列之自定义鼠标风格的实现
在我们开发的过程中,有时需要我们来自定义鼠标的形状和大小,刚巧前一阵子正好用到了这个技术,找了好多资料,基本上都是黑白色的鼠标风格实现,而我要的则是自定义大小和彩色风格的光标样式.百度上的资源又太少, ...