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矩阵快速幂的更多相关文章

  1. HDU.2640 Queuing (矩阵快速幂)

    HDU.2640 Queuing (矩阵快速幂) 题意分析 不妨令f为1,m为0,那么题目的意思为,求长度为n的01序列,求其中不含111或者101这样串的个数对M取模的值. 用F(n)表示串长为n的 ...

  2. HDU 5667 构造矩阵快速幂

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

  3. HDU 6185 Covering 矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6185 题意:用 1 * 2 的小长方形完全覆盖 4 * n的矩形有多少方案. 解法:小范围是一个经典题 ...

  4. HDU 2157(矩阵快速幂)题解

    How many ways?? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. HDU 6395 分段矩阵快速幂 HDU 6386 建虚点+dij

    http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others)    Me ...

  6. HDU 6470 【矩阵快速幂】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6470 写这道题是为了让自己不要忘记矩阵快速幂如何推出矩阵式子的. 注意 代码是TLE的!! #incl ...

  7. HDU 5607 graph 矩阵快速幂 + 快速幂

    这道题得到了学长的助攻,其实就是一个马尔科夫链,算出一步转移矩阵进行矩阵快速幂就行了,无奈手残 这是我第一回写矩阵快速幂,写的各种毛病,等到调完了已经8点44了,交了一发,返回PE,(发现是少了换行) ...

  8. HDU 1575(裸矩阵快速幂)

    emmmmm..就是矩阵快速幂,直接附代码: #include <cstdio> using namespace std; ; ; struct Matrix { int m[maxn][ ...

  9. hdu 6395Sequence【矩阵快速幂】【分块】

    Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total ...

随机推荐

  1. 关于struts2中ActionContext类的作用

    关于struts2中ActionContext类的作用有三个: 1.获取三大作用域对象及页面参数 2.是struts标签的上下文对象 3.ThreadLocal内装的就是ActionContext 怎 ...

  2. oracle老是出现监听错误

    解决方法之一: 点击开始-->选择程序--->选中你安装的oracle版本-->选中配置与移植工具-->选中Net Configuration Assistant-->在 ...

  3. [leetcode]333. Largest BST Subtree最大二叉搜索树子树

    Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest mea ...

  4. StringUtils学习

    commons-lang3-3.5.jar

  5. php下的原生ajax请求

    浏览器中为我们提供了一个JS对象XMLHttpRequet,它可以帮助我们发送HTTP请求,并接受服务端的响应. 意味着我们的浏览器不提交,通过JS就可以请求服务器.   ajax(Asynchron ...

  6. mysql只保留一条有效数据,删除其他重复的数据

    delete from TableName where id in( SELECT ID FROM(SELECT * FROM TableName t0WHERE(t0.Field1,t0.Field ...

  7. MySql中4种批量更新的方法

    最近在完成MySql项目集成的情况下,需要增加批量更新的功能,根据网上的资料整理了一下,很好用,都测试过,可以直接使用. mysql 批量更新共有以下四种办法 1..replace into 批量更新 ...

  8. Shell编程实例

    一.简介 从程序员的角度来看, Shell本身是一种用C语言编写的程序,从用户的角度来看,Shell是用户与Linux操作系统沟通的桥梁.用户既可以输入命令执行,又可以利用 Shell脚本编程,完成更 ...

  9. 调用父类构造器:super

    import static java.lang.System.*; class Base{ public String name; public double weight; public Base( ...

  10. [freeCodeCamp] solution to JUGGLING ASYNC

    Here's the official solution in case you want to compare notes: var http = require('http') var bl = ...