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 ...
随机推荐
- 多种语言书写 “ HelloWorld ”
最基本的C: #include<stdio.h> int main(int argc, char const *argv[]) { printf("HelloWorld\n&qu ...
- PAT 乙级 1024
题目 题目地址:PAT 乙级 1024 题解 模拟题,重点需要考虑到各种不同情况:简单来说一下: 因为输入格式固定,所以把不同的部分分别存储和处理可以在很大程度上简化运算:其中需要考虑最多的就是小数部 ...
- 【点分树】codechef Yet Another Tree Problem
已经连咕了好几天博客了:比较经典的题目 题目大意 给出一个 N 个点的树和$K_i$, 求每个点到其他所有点距离中第 $K_i$ 小的数值. 题目分析 做法一:点分树上$\log^3$ 首先暴力做法: ...
- celery:Unrecoverable error: AttributeError("'unicode' object has no attribute 'iteritems')
环境描述 python2+django1.9下使用celery异步处理耗时请求. celery使用的是celery-with-redis这个第三方库,版本号为3.0. pip install cele ...
- Mysql操作方法类
帮助类: using System; using System.Collections.Generic; using System.Data; using System.Linq; using Sys ...
- Python 正则表达式 search vs match
search()和match()函数都是正则表达式中的匹配函数,二者有何区别呢? 1.match()从string的开始位置进行正则匹配,即从0位置开始匹配,若匹配上则返回一个match对象,否则返回 ...
- nginx的缓存服务
都知道缓存的目的是为了减小服务端的压力,可以在客户端直接取到数据 客户端---------------nginx(代理缓存)------------------服务端 代理缓存的描述: 就是客户端发送 ...
- php实现的三个常用加密解密功能函数示例
目录 算法一: 算法二: 算法三(改进第一个加密之后的算法) 本文实例讲述了php实现的三个常用加密解密功能函数.分享给大家供大家参考,具体如下: 算法一: //加密函数 function lock_ ...
- Sublime Text配置python以及快捷键总结
1.打开Tools > Build System > New Build System.. 2.点击New Build System后,会生成一个空配置文件,在这个配置文件内覆盖配置信息, ...
- Linux程序编辑器
重点回顾:Linux底下的配置文件多为文本文件,故使用vim即可进行设定编辑: vim可视为程序编辑器,可用以编辑shell script,配置文件等,避免打错字 vi为所有unix like的操作系 ...