HDU [P5015] 233 Matrix
矩阵快速幂
按列递推
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#define ll long long
using namespace std;
const int MOD = 10000007;
int n, m;
struct Matrix {
ll num[15][15];
void clear() {
memset(num, 0, sizeof(num));
}
void unit() {
clear();
for(int i = 0; i <= n + 1; i++) num[i][i] = 1;
}
Matrix operator * (const Matrix & b) {
Matrix ans;
ans.clear();
for(int i = 0; i <= n + 1; i++) {
for(int j = 0; j <= n + 1; j++) {
ll tmp = 0ll;
for(int k = 0; k <= n + 1; k++) {
tmp += num[i][k] * b.num[k][j];
}
ans.num[i][j] = tmp % MOD;
}
}
return ans;
}
Matrix operator ^ (ll k) {
Matrix ans, tt = (*this);
ans.unit();
while(k) {
if(k & 1ll) ans = ans * tt;
tt = tt * tt;
k >>= 1;
}
return ans;
}
void print() {
for(int i = 0; i <= n + 1; i ++) {
for(int j = 0; j <= n + 1; j++) {
printf("%lld ", num[i][j]);
}
printf("\n");
}
}
};
int main() {
while(~scanf("%d %d", &n, &m)) {
Matrix a, b;
a.clear(); b.clear();
for(int i = 0; i <= n + 1; i++) {
if(i <= n) a.num[i][0] = 10;
a.num[i][n + 1] = 1;
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= i; j++) {
a.num[i][j] = 1;
}
}
b.num[0][0] = 23; b.num[n + 1][0] = 3;
for(int i = 1; i <= n; i++) scanf("%lld", &b.num[i][0]);
b = (a ^ m) * b;
cout << b.num[n][0] << endl;
}
return 0;
}
HDU [P5015] 233 Matrix的更多相关文章
- HDU - 5015 233 Matrix(杨辉三角/前缀+矩阵快速幂)
233 Matrix In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23 ...
- HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂
先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html http://www.cppblog.com/acronix/archive/20 ...
- hdu 5015 233 Matrix (矩阵高速幂)
233 Matrix Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
- 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 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
题意:给定一个矩阵的第0列的第1到n个数,第一行第1个数开始每个数分别为233, 2333........,求第n行的第m个数. 分析: 其实也没那么难,自己想了半天还没往对的方向想,m最大1e9,应 ...
- Spring-1-I 233 Matrix(HDU 5015)解题报告及测试数据
233 Matrix Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descript ...
- 233 Matrix(hdu5015 矩阵)
233 Matrix Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
随机推荐
- SummerVocation_Learning--java的String 类
java中String属于java.lang的package包,是一个类.代表不可变的字符序列. String类的常见构造方法: String(String original),创建一个对象为orig ...
- 五、Shell 基本运算符
Shell 基本运算符 Shell 和其他编程语言一样,支持多种运算符,包括: 算数运算符 关系运算符 布尔运算符 字符串运算符 文件测试运算符 原生bash不支持简单的数学运算,但是可以通过其他命令 ...
- java.lang.ClassCastException: com.sun.proxy.$Proxy53 cannot be cast to cn.service.impl.WorkinggServiceImpl
java.lang.ClassCastException: com.sun.proxy.$Proxy53 cannot be cast to cn.service.impl.WorkinggServi ...
- php 单冒号 、双冒号的用法
单冒号: 常用与三元运算,如:$result = $str ? $str : $str1; 双冒号: 1,当调用静态属性和静态方法时 2,当调用自身类或者父类的属性或者方法时
- docker 学习(2)
docker容器中安装vim ubuntu 中默认未装vim,docker run ubuntu vim 出现: container_linux.go:247: starting container ...
- (洛谷)P1019 单词接龙
题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的"龙"(每个单词都最多在"龙" ...
- poj 23565-Find a multiple
Find a multiple The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each ...
- CodeForces 781E Andryusha and Nervous Barriers 线段树 扫描线
题意: 有一个\(h \times w\)的矩形,其中有\(n\)个水平的障碍.从上往下扔一个小球,遇到障碍后会分裂成两个,分别从障碍的两边继续往下落. 如果从太高的地方落下来,障碍会消失. 问从每一 ...
- Install ADDS on Windows Server 2012 R2 with PowerShell
Install ADDS on Windows Server 2012 R2 with PowerShell Posted by ethernuno on 20/04/2014 In this tut ...
- OpenStack之Glance源码简析
Glance简介 OpenStack镜像服务器是一套虚拟机镜像发现.注册.检索. glance架构图: Glance源码结构: glance/api:主要负责接收响应镜像管理命令的Restful请求, ...