233 Matrix

Time Limit: 10000/5000 MS (Java/Others)    Memory
Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1399    Accepted Submission(s): 826

Problem Description
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
a0,1 = 233,a0,2 = 2333,a0,3 = 23333...) Besides, in 233 matrix, we got ai,j = ai-1,j +ai,j-1( i,j ≠ 0). Now you have known a1,0,a2,0,...,an,0, could you tell
me an,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 ≤ 109). The second line contains n integers, a1,0,a2,0,...,an,0(0 ≤ ai,0 < 231).
 
Output
For each case, output an,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 <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#define LL long long
using namespace std;
const long long MAXN = 15;
const long long mod = 10000007;
struct Matrix
{
long long mat[MAXN][MAXN], n;
Matrix(){memset(mat, 0, sizeof(mat));}
Matrix operator * (Matrix & rhs)
{
Matrix res; res.n = n;
for(long long i=1;i<=n;i++)
{
for(long long j=1;j<=n;j++)
{
for(long long k=1;k<=n;k++)
{
(res.mat[i][j] += (mat[i][k] * rhs.mat[k][j]) % mod) %= mod;
}
}
}
return res;
}
};
Matrix pow_mod(Matrix a, long long b)
{
Matrix res; res.n = a.n;
for(long long i=1;i<=a.n;i++) res.mat[i][i] = 1;
while(b)
{
if(b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
long long a[MAXN], n, m;
int main()
{
while(scanf("%I64d%I64d", &n, &m)!=EOF)
{
for(long long i=1;i<=n;i++) scanf("%I64d", &a[i]);
Matrix ans; ans.n = n + 2;
for(long long i=1;i<=n + 1;i++)
{
ans.mat[i][1] = 10;
for(long long j=2;j<=i;j++)
{
ans.mat[i][j] = 1;
}
}
for(long long i=1;i<=n+1;i++) ans.mat[n+2][i] = 0;
for(long long i=1;i<=n+2;i++) ans.mat[i][n+2] = 1;
ans = pow_mod(ans, m);
/* for(long long i=1;i<=n+2;i++)
{
for(long long j=1;j<=n+2;j++)
cout << ans.mat[i][j] << ' ';
cout <<endl;
}*/
a[0] = 23, a[n+1] = 3;
long long rs = 0;
for(long long i=1;i<=n+2;i++) (rs += a[i-1] * ans.mat[n+1][i]) %= mod;
printf("%I64d\n", rs);
}
return 0;
}

HDU 5015 233Matrix (构造矩阵)的更多相关文章

  1. 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] ...

  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. hdu 5015 233 Matrix(构造矩阵)

    http://acm.hdu.edu.cn/showproblem.php?pid=5015 由于是个二维的递推式,当时没有想到能够这样构造矩阵.从列上看,当前这一列都是由前一列递推得到.依据这一点来 ...

  4. hdu 5015 233矩阵快速幂

    http://acm.hdu.edu.cn/showproblem.php?pid=5015 需要构造一个 n+2 维的矩阵. 就是要增加一维去维护2333这样的序列. 可以发现 2333 = 233 ...

  5. HDU 3306 Another kind of Fibonacci ---构造矩阵***

    Another kind of Fibonacci Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  6. HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...

  7. HDU 5667 构造矩阵快速幂

    HDU 5667 构造矩阵快速幂 题目描述 解析 我们根据递推公式 设 则可得到Q的指数关系式 求Q构造矩阵 同时有公式 其中φ为欧拉函数,且当p为质数时有 代码 #include <cstdi ...

  8. Number Sequence(HDU 1005 构造矩阵 )

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. hdu 5015 矩阵快速幂(可用作模板)

    转载:http://blog.csdn.net/wdcjdtc/article/details/39318847 之前各种犯傻 推了好久这个东西.. 后来灵关一闪  就搞定了.. 矩阵的题目,就是构造 ...

随机推荐

  1. 联想 Vibe Shot(Z90-3) 免recovery 获取ROOT权限 救砖 VIBEUI V3.1_1625

    >>>重点介绍<<< 第一:本刷机包可卡刷可线刷,刷机包比较大的原因是采用同时兼容卡刷和线刷的格式,所以比较大第二:[卡刷方法]卡刷不要解压刷机包,直接传入手机后用 ...

  2. UI布局只关乎三件事情:尺寸、位置、组织

    UI布局只关乎三件事情:尺寸.位置.组织. 组织分为两类: 单元组织: 集合组织: 混合组织.

  3. 设置CAD显示窗体

    AcDbViewTableRecord view; AcGePoint3d max = acdbHostApplicationServices()->workingDatabase()-> ...

  4. 用Docker实现nginx多端口

    一.安装docker 需要阿里的epel源,需要联网 [root@bogon ~]#yum -y install docker [root@bogon ~]#systemctl start docke ...

  5. docker 1-->docker machine 转载

    Docker Machine 是 Docker 官方编排(Orchestration)项目之一,负责在多种平台上快速安装 Docker 环境. Docker Machine 是一个工具,它允许你在虚拟 ...

  6. IOS上MediaPlayer framework实现视频播放

    播放电影文件: iOS sdk中可以使用MPMoviePlayerController来播放电影文件.但是在iOS设备上播放电影文件有严格的格式要求,只能播放下面两个格式的电影文件. • H.264 ...

  7. 数列分块入门1-9 By hzwer

    声明 持续更新,因为博主也是正在学习分块的知识,我很菜的,菜的抠$jio$ 写在前面 分块是个很暴力的算法,但却比暴力优秀的多,分块算法的时间复杂度一般是根号的,他的主要思想是将一个长度是$n$的数列 ...

  8. 洛谷 1097 统计数字(NOIp2007提高组T1)

    [题解] 排个序然后扫一遍进行统计即可. #include<cstdio> #include<algorithm> #include<cstring> #defin ...

  9. 马拉车,O(n)求回文串

    马拉车,O(n)求回文串 对整个马拉车算法步骤做个总结: 第一步:将每个原字母用两个特殊字符包围如: aaa --> #a#a#a# abab -->#a#b#a#b 同时可以由这个翻倍的 ...

  10. PAT 1085 PAT单位排行

    每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤10^5),即考生人数.随后 N 行,每行按下列格式给出一个考生的信 ...