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个环不在棒子上.每个 ...
随机推荐
- PHPCMS快速建站系列之在线留言
有两种方法 第一种方法: 利用留言板插件,在后台模板中,安装留言板插件使用,这里先不展开. 第二种方法: 表单向导的适用场合: 如果一个前台页面只是为了提交表单数据,那么就非常适合适用表单向导的功能, ...
- select标签模拟placeholder属性与一般操作(最重要的是ios某一项被选中的兼容)
1.为了统一样式,常常要模拟placeholder <select> <option disabled selected hidden>请选择</option> & ...
- 【JZOJ4869】【NOIP2016提高A组集训第9场11.7】平均数
题目描述 数据范围 解法 二分答案. 对于一个答案mid,要求出区间平均数小于mid的个数ans. 给所有数减去mid,那么问题转化为求出所有区间和为负数的个数. 对于一个区间[l,r],如果sum[ ...
- BZOJ 4551树题解
好吧,洛谷的数据比较水暴力就可以过....(而且跑到飞快) 不过(BZ水不过去)还是讲讲正规的做法. 其实一眼可以看出可以树剖,但是,码起来有点麻烦. 其实有一种更简单的离线做法. 我们很容易联想到并 ...
- python的str,unicode对象的encode和decode方法, Python中字符编码的总结和对比bytes和str
python_2.x_unicode_to_str.py a = u"中文字符"; a.encode("GBK"); #打印: '\xd6\xd0\xce\xc ...
- find 使用搜集
find:-atime +n/-n:表示访问或执行时间大于或小于n天的文件-ctime +n/-n:表示写入.更改inode属性的时间大于或小于n天的文件-mtime +n/-n:表示写入时间大于或小 ...
- COGS 775 山海经
COGS 775 山海经 思路: 求最大连续子段和(不能不选),只查询,无修改.要求输出该子段的起止位置. 线段树经典模型,每个节点记录权值和sum.左起最大前缀和lmax.右起最大后缀和rmax.最 ...
- android学习——Android Layout标签之-viewStub,requestFocus,merge,include
定义Android Layout(XML)时,有四个比较特别的标签是非常重要的,其中有三个是与资源复用有关,分别是<viewStub/>, <requestFocus />, ...
- @codeforces - 1186F@ Vus the Cossack and a Graph
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 点 m 边的图(n, m<=10^6),记第 ...
- 使用php函数ini_set()重新设置某个配置的设置值
使用PHP的ini_set()函数 ini_set (PHP 4, PHP 5, PHP 7) ini_set — 为一个配置选项设置值 说明 string ini_set ( string $var ...