HDU 5015 233Matrix (构造矩阵)
233 Matrix
Time Limit: 10000/5000 MS (Java/Others) Memory
Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1399 Accepted Submission(s): 826
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?
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).
1 1
1
2 2
0 0
3 7
23 47 16
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 (构造矩阵)的更多相关文章
- 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] ...
- 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 5015 233 Matrix(构造矩阵)
http://acm.hdu.edu.cn/showproblem.php?pid=5015 由于是个二维的递推式,当时没有想到能够这样构造矩阵.从列上看,当前这一列都是由前一列递推得到.依据这一点来 ...
- hdu 5015 233矩阵快速幂
http://acm.hdu.edu.cn/showproblem.php?pid=5015 需要构造一个 n+2 维的矩阵. 就是要增加一维去维护2333这样的序列. 可以发现 2333 = 233 ...
- HDU 3306 Another kind of Fibonacci ---构造矩阵***
Another kind of Fibonacci Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- 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 ...
- HDU 5667 构造矩阵快速幂
HDU 5667 构造矩阵快速幂 题目描述 解析 我们根据递推公式 设 则可得到Q的指数关系式 求Q构造矩阵 同时有公式 其中φ为欧拉函数,且当p为质数时有 代码 #include <cstdi ...
- Number Sequence(HDU 1005 构造矩阵 )
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 5015 矩阵快速幂(可用作模板)
转载:http://blog.csdn.net/wdcjdtc/article/details/39318847 之前各种犯傻 推了好久这个东西.. 后来灵关一闪 就搞定了.. 矩阵的题目,就是构造 ...
随机推荐
- Myeclipse2014安装&破解激活
市场上很多JavaWeb的IDE比如Idea(听说用好开发效率会很高),eclipse(插件丰富还免费),但是对于初学者还是为了提高学习的效率(Myeclipse创建web项目的时候可以自动生成一些配 ...
- leetcode375 Guess Number Higher or Lower II
思路: dp. https://leetcode.com/problems/guess-number-higher-or-lower-ii/discuss/ 实现: class Solution { ...
- Android Bitmap转换WebP图片导致损坏的分析及解决方案
背景 作为移动领域所力推的图片格式,WebP图片在商业领域证明了其应有的价值.基于其他格式的横向对比,其在压缩性能表现,及还原度极为优秀,节省大量的带宽开销.基于可观的效益比,团队早前已开始磋商将当前 ...
- 第一次创建svn的项目的使用方法
1.第一步.在服务器上创建svn项目,将开发人人员你的账号密码添加上去. 2.第二步.开始在本地创建一个文件夹,点文件夹,右键->tortoisSVN->repo-brower 填写svn ...
- struts2配置文件加载顺序
struts2配置文件加载顺序: struts-default.xml/ struts-plugin.xml/ struts.xml/ struts.properties/ web.xml
- linux初步学习有感
经过了一段时间对linux的接触,从最开始接触到的deepin到后来我最喜欢的KaliLinux,感受到了这个我曾经并不了解的操作系统的独特魅力. 我是到了大学才知道linux这个系统的,但是在小时候 ...
- 设置Python解析器
如果同时安装了多个Python,如 Python2.7 和 Python3.7 .如果某些特殊原因(比如有些框架只能在Python2.7中使用),需要修改程序在 Python2.7 下运行,即可设置P ...
- stall and flow separation on airfoil or blade
stall stall and flow separation Table of Contents 1. Stall and flow separation 1.1. Separation of Bo ...
- 关于一个css布局的小记录
这里我们采用一种最简单的 方式,至少我目前认为最简单的方式,使用flex布局来实现 下面是html结构: <div class="box1"> <div clas ...
- Spring 获取当前activeProfile
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext()) ...