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. C#整合VS2010和NUnit

    软件下载 .Net单元测试工具 NUnit下载:http://www.nunit.org/index.php?p=download,最新的为NUnit-2.6.0.12051.msi,下载安装. VS ...

  2. python yield 浅析-转载

    如何生成斐波那契數列 斐波那契(Fibonacci)數列是一个非常简单的递归数列,除第一个和第二个数外,任意一个数都可由前两个数相加得到.用计算机程序输出斐波那契數列的前 N 个数是一个非常简单的问题 ...

  3. org.Hs.eg.db包简介(转换NCBI、ensemble等数据库中基因ID,symbol等之间的转换)

    1)安装载入 ------------------------------------------- if("org.Hs.eg.db" %in% rownames(install ...

  4. wireshark使用相关问题

    问题1: 打开wireshark,没有出现过滤器 解决1: 使用管理员方式登录 过滤: http and ip.src == 192.168.0.10 and ip.dst == 192.168.0. ...

  5. count++线程安全与 synchronized对性能影响的测试

    一个计时器,同时开启100个线程,每个线程休眠1ms钟后,将全局静态变量count加1,这100个线程创建完之后,休眠500ms,计算总耗时,程序如下: public class Counter { ...

  6. SQL dialect is not configured

    在Idea中,xml配置文件报错:SQL dialect is not configured 解决方法如下: 在Idea中,在报错的地方按alt+enter,然后点击Generic配置dialect即 ...

  7. DOS中符号的英文对照

    --------------siwuxie095 1..:point 或 dot 或 period 或 full stop 2.空格:space 或 blank ------------------- ...

  8. PHP的zip、unzip类详解

    1.打开一个ZIP包,用于读取.写入或修改 open(string $filename [, int $flags]) $filename - 文件名 $flags - 打开模式 ZIPARCHIVE ...

  9. 安装Ubuntu后一些准备

    一些基础 安装的时候,先不选镜像就可以避开简易安装. 更改root密码:sudo passwd root 更改源,更新,不行就打断在更新 安装vim 改为unity模式,安装VMware Tools, ...

  10. ObjC.instancetype

    1. instancetype http://nshipster.com/instancetype/ 2. Objc的扩展 http://clang.llvm.org/docs/LanguageExt ...