HDU - 5015 233 Matrix (矩阵快速幂)
InputThere are multiple test cases. Please process till EOF.
For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 10 9). The second line contains n integers, a 1,0,a 2,0,...,a n,0(0 ≤ a i,0 < 2 31).OutputFor each case, output a n,m mod 10000007.Sample Input
1 1
1
2 2
0 0
3 7
23 47 16
Sample Output
234
2799
72937 题意:
a[i][j]=a[i-1][j]+a[i][j-1];
a[0][1]=233,a[0][2]=2333,a[0][3]=23333,......
a[1][0]到a[n][0]由输入给出,求a[n][m];
思路:
本来打算直接用a[i][j]=a[i-1][j]+a[i][j-1]作为公式进行推导,发现并不可行。
实际上是直接对每一列进行操作。
写完这题,大概矩阵快速幂才是真的入门。

#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define debug(a,i) cout<<#a<<"["<<i<<"] = "<<a[i]<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int maxm = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); ll num[]; struct Matrix{
ll mp[][];
};
Matrix mul(Matrix a,Matrix b,int n){
Matrix ans;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
ans.mp[i][j]=;
for(int k=;k<=n;k++){
ans.mp[i][j]+=a.mp[i][k]*b.mp[k][j];
}
ans.mp[i][j]%=mod;
}
}
return ans;
} Matrix q_pow(Matrix a,int b,int n){
Matrix ans;
memset(ans.mp,,sizeof(ans.mp));
for(int i=;i<=n;i++){
ans.mp[i][i]=;
}
while (b){
if(b&){
ans=mul(ans,a,n);
}
b>>=;
a=mul(a,a,n);
}
return ans;
} int main()
{
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin); int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<=n;i++){
scanf("%lld",&num[i]);
}
Matrix exa;
memset(exa.mp,,sizeof(exa.mp));
int t=;
exa.mp[n+][n+]=;
for(int i=;i<=n+;i++){
exa.mp[i][]=;exa.mp[i][n+]=;
for(int j=;j<=t;j++){
exa.mp[i][j+]=;
}
t++;
}
exa=q_pow(exa,m,n+);
ll ans=;
num[]=;num[n+]=;
for(int i=;i<=n+;i++){
ans+=exa.mp[n+][i]*num[i-];
ans%=mod;
}
printf("%lld\n",ans); } return ;
}
HDU - 5015 233 Matrix (矩阵快速幂)的更多相关文章
- 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] ...
- 233 Matrix 矩阵快速幂
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
- 233 Matrix(矩阵快速幂+思维)
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
- HDU5015 233 Matrix —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-5015 233 Matrix Time Limit: 10000/5000 MS (Java/Others) Memor ...
- HDU.1575 Tr A ( 矩阵快速幂)
HDU.1575 Tr A ( 矩阵快速幂) 点我挑战题目 题意分析 直接求矩阵A^K的结果,然后计算正对角线,即左上到右下对角线的和,结果模9973后输出即可. 由于此题矩阵直接给出的,题目比较裸. ...
- HDU5015 233 Matrix(矩阵高速幂)
HDU5015 233 Matrix(矩阵高速幂) 题目链接 题目大意: 给出n∗m矩阵,给出第一行a01, a02, a03 ...a0m (各自是233, 2333, 23333...), 再给定 ...
- hdu 3117 Fibonacci Numbers 矩阵快速幂+公式
斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...
- HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂
先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html http://www.cppblog.com/acronix/archive/20 ...
- HDU 2842 (递推+矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个 ...
随机推荐
- QT 引用之前项目模板导致计算速度严重下降
最近做RRT规划算法,在新建工程中测试时,每一个周期大概花费20MS,但是当我把算法移植到之前写的工程模板中时,计算效率相当低,变为500毫秒.期初是以为代码有问题,然后就逐句查找,发现代码并没有问题 ...
- hdu5137 枚举删点
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ; ; ...
- 笔记:在 Windows 10 WSL Ubuntu 18.04 安装 Odoo12 (2019-06-09)
笔记:在 Windows 10 WSL Ubuntu 18.04 安装 Odoo12 原因 为了和服务器一样的运行环境. 使用 Ubuntu 运行 Odoo 运行更快. 方便使用 Windows 10 ...
- iOS小技巧:用runtime 解决UIButton 重复点击问题
http://www.cocoachina.com/ios/20150911/13260.html 作者:uxyheaven 授权本站转载. 什么是这个问题 我们的按钮是点击一次响应一次, 即使频繁的 ...
- Xcode无法退出,报错提示 The document “xxx.h” could not be saved. The file doesn’t exist.
记录一个问题 场景:Xcode编辑一个工程时直接在工程内部修改了某个目录的文件夹名字,而后删除了其下的某 .h.m 文件 之后总是提示上述错误且无法强制退出Xcode,clean等操作基本没用 查找本 ...
- lattice planner 规划详解
大家好,我是来自百度智能驾驶事业群的许珂诚.今天很高兴能给大家分享Apollo 3.0新发布的Lattice规划算法. Lattice算法隶属于规划模块.规划模块以预测模块.routing模块.高精地 ...
- 从零学React Native之05混合开发
本篇文章,我们主要讨论如何实现Android平台的混合开发. RN给Android端发送消息 首先打开Android Studio, Open工程, 在React Native项目目录下选择andro ...
- 【[Offer收割]编程练习赛15 A】 偶像的条件
[题目链接]:http://hihocoder.com/contest/offers15/problem/1 [题意] [题解] 把3个数组的元素全都合并在一个数组里面; (当然你要记录每个数字原本是 ...
- PyTorch中view的用法
相当于numpy中resize()的功能,但是用法可能不太一样. 我的理解是: 把原先tensor中的数据按照行优先的顺序排成一个一维的数据(这里应该是因为要求地址是连续存储的),然后按照参数组合成其 ...
- iptables [-j target/jump] 常用的处理动作
-j 参数用来指定要进行的处理动作,常用的处理动作包括:ACCEPT.REJECT.DROP.REDIRECT.MASQUERADE.LOG.DNAT.SNAT.MIRROR.QUEUE.RETURN ...