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 ...
随机推荐
- apply和call用法
资料来源:http://blog.csdn.net/business122/article/details/8000676 Js apply方法详解 我在一开始看到javascript的函数apply ...
- 首届阿里巴巴在线技术峰会,9位大V演讲整理!
https://yq.aliyun.com/articles/57826 感谢参加阿里巴巴在线技术峰会.7月19日的3场专家分享:Blink.Docker.电商互动:7月20日的云数据库十大经典案 例 ...
- Ubuntu下Anaconda3的安装
1)去https://www.anaconda.com/download/#download下载Anaconda安装文件(python3.6的版本). 2)进入到Anaconda3-5.0.1-Lin ...
- select语法图
- SharePoint 2010 图表控件
需求: 统计每周的事件创建数量及关闭数量 以折线的形式显示 一张图表显示两条折线 知识点: 图表控件的使用 外部内容类型 数据库(sql)view(数据源) 结果:
- springmvc后台生成验证码
url http://localhost:8080/admin/getCode http://localhost:8080/admin/checkCode controller package com ...
- bootstrap下拉框的例子,提示Error: Bootstrap's JavaScript requires jQuery
bootstrap很多js依赖jquery,所以需要引入jquery 遇到的问题: 页面访问提示:Error: Bootstrap's JavaScript requires jQuery 解 ...
- C++调试帮助
assert预处理宏 assert是一种预处理宏,所谓预处理其实是一个预处理变量,其行为类似于内联函数,assert宏使用一个表达式作为其条件: assert(expr) 首先是对expr进行求值,如 ...
- Python bool() 函数
Python bool() 函数 Python 内置函数 描述 bool() 函数用于将给定参数转换为布尔类型,如果没有参数,返回 False. bool 是 int 的子类. 语法 以下是 boo ...
- Island Transport
Island Transport http://acm.hdu.edu.cn/showproblem.php?pid=4280 Time Limit: 20000/10000 MS (Java/Oth ...