hdu 5015 233矩阵快速幂
http://acm.hdu.edu.cn/showproblem.php?pid=5015
需要构造一个 n+2 维的矩阵。
就是要增加一维去维护2333这样的序列。
可以发现 2333 = 233*10 + 3
所以增加了一维就 是1, 然后就可以全部转移了。
10 0 0 0 0 ... 1
1 1 0 0 0 ..... 0
0 1 1 0 ... 0
. . .. . .. . .. .. .. . .
0 0 0 0 0 .... 1,
矩阵乘法+快速幂优化递推。
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
const int N = 15;
const int modo = 10000007;
int k,m;
struct Matrix{
LL mat[N][N];
void unit(){
clr0(mat);
for (int i=0;i<=k;++i) mat[i][i]=1;
}
Matrix operator*(Matrix b){
Matrix c;
memset(c.mat,0,sizeof(c.mat));
for (int i=0;i<=k;++i)
for (int l=0;l<=k;++l)
if (mat[i][l])
for (int j=0;j<=k;++j)
c.mat[i][j] = (c.mat[i][j] + mat[i][l] * b.mat[l][j]) % modo;
return c;
}
};
Matrix operator^(Matrix a,int m){
Matrix t;
t.unit();
while(m){
if (m&1) t=t*a;
a=a*a;
m>>=1;
}
return t;
}
int b[15];
int main (){
while(~RD2(k,m)){
b[0] = 233;
for(int i = 1;i <= k;++i)
RD(b[i]);
b[++k] = 3;
Matrix c;
c.unit();
for(int i = 0;i < k;++i){
for(int j = 0;j < i;++j){
c.mat[i][j] = 1;
}
}
c.mat[0][0] = 10,c.mat[0][k] = 1;
// for(int i = 0;i <= k;++i){
// for(int j = 0;j <= k;++j){
// cout<<c.mat[i][j]<<' ';
// }
// cout<<endl;
// }
Matrix d = c^m; int ans = 0;
for(int i = 0;i <= k;++i)
ans = (ans + d.mat[k-1][i] * b[i])%modo;
cout<<ans<<endl;
}
return 0;
}
hdu 5015 233矩阵快速幂的更多相关文章
- HDU.2640 Queuing (矩阵快速幂)
HDU.2640 Queuing (矩阵快速幂) 题意分析 不妨令f为1,m为0,那么题目的意思为,求长度为n的01序列,求其中不含111或者101这样串的个数对M取模的值. 用F(n)表示串长为n的 ...
- HDU 5667 构造矩阵快速幂
HDU 5667 构造矩阵快速幂 题目描述 解析 我们根据递推公式 设 则可得到Q的指数关系式 求Q构造矩阵 同时有公式 其中φ为欧拉函数,且当p为质数时有 代码 #include <cstdi ...
- HDU 6185 Covering 矩阵快速幂
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6185 题意:用 1 * 2 的小长方形完全覆盖 4 * n的矩形有多少方案. 解法:小范围是一个经典题 ...
- HDU 2157(矩阵快速幂)题解
How many ways?? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 6395 分段矩阵快速幂 HDU 6386 建虚点+dij
http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others) Me ...
- HDU 6470 【矩阵快速幂】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6470 写这道题是为了让自己不要忘记矩阵快速幂如何推出矩阵式子的. 注意 代码是TLE的!! #incl ...
- HDU 5607 graph 矩阵快速幂 + 快速幂
这道题得到了学长的助攻,其实就是一个马尔科夫链,算出一步转移矩阵进行矩阵快速幂就行了,无奈手残 这是我第一回写矩阵快速幂,写的各种毛病,等到调完了已经8点44了,交了一发,返回PE,(发现是少了换行) ...
- HDU 1575(裸矩阵快速幂)
emmmmm..就是矩阵快速幂,直接附代码: #include <cstdio> using namespace std; ; ; struct Matrix { int m[maxn][ ...
- hdu 6395Sequence【矩阵快速幂】【分块】
Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total ...
随机推荐
- spring 3.x + hibernate4.x 实现数据延迟加载
Spring为我们解决Hibernate的Session的关闭与开启问题. Hibernate 允许对关联对象.属性进行延迟加载,但是必须保证延迟加载的操作限于同一个 Hibernate Sess ...
- Codeforces 710C. Magic Odd Square n阶幻方
C. Magic Odd Square time limit per test:1 second memory limit per test:256 megabytes input:standard ...
- dir/
dos窗口输入dir命令是显示磁盘目录命令: addslashes()使用反斜线转义字符串: exec($command,$output,$return)执行一个外部程序 $command:要执行的命 ...
- [远程] windows 2008 server设置了共享文件夹,并且共享给了everyone,但是还是无法访问,怎么解决呢?
还需要设置另外一个地方,将用户加到MSAppAccess这个组里去
- swift 设置string 中汉字中变色等处理代码
我们在做弹窗 或者显示label string的时候经常会用到字体变色 变大 等特殊处理, swift中提供一个函数 NSMutableAttributedString 使用方法简介 var main ...
- 3、基本的Get和Post访问(含代理请求)
Get方式访问 HttpClient hc = new DefaultHttpClient(); HttpUriRequest request = new HttpGet("http://w ...
- redmine2.6.5 邮件配置
打开configuration.xml (路径:apps/redmine/htdocs/config/) production: email_delivery: delivery_method: :s ...
- Myeclipse如何更新maven
选中项目-->右键-->Maven4MyEclipse-->Update Project-->勾选Force update of.....就ok了
- jquery报.live() is not a function的解决方法
jquery报.live() is not a function的解决方法: jquery中的live()方法在jquery1.9及以上的版本中已被废弃了,如果使用,会抛出TypeError: $(. ...
- 美团点评2017校招笔试真题-算法工程师B
美团点评2017校招笔试真题-算法工程师B 1.以下关于经典的k-means聚类的说法哪个是错误的? A:k-means聚类算法是全局收敛的 B:k-means的聚类结果和初始聚类中心点的选取有关 C ...