hdu-5015-233 Matrix-矩阵
非常显然矩阵的第一列为:
0
a[1]
a[2]
a[3]
a[4]
我们转化一下,转化为
23
a[1]
a[2]
a[3]
a[4]
3
那么由第一列转移到第二列则为
23*10+3
a[1]+23*10+3
a[2]+a[1]+23*10+3
a[3]+a[2]+a[1]+23*10+3
a[4]+a[3]+a[2]+a[1]+23*10+3
3
非常显然转移矩阵A就出来了:
10 0 0 0 0 1
10 1 0 0 0 1
10 1 1 0 0 1
10 1 1 1 0 1
10 1 1 1 1 1
0 0 0 0 0 1
那么最后一列就是A的m次方*第一列。
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define maxn 110000
#define mod 10000007
#define LL __int64
struct matrix
{
LL mat[15][15];
matrix()
{
memset(mat,0,sizeof(mat));
}
};
int a[11];
int n;
matrix mul(matrix A,matrix B)
{
matrix C;
int i,j,k;
for(i=1; i<=n+2; i++)
{
for(j=1; j<=n+2; j++)
{
for(k=1; k<=n+2; k++)
{
C.mat[i][j]=(C.mat[i][j]+A.mat[i][k]*B.mat[k][j])%mod;
}
}
}
return C;
}
matrix powmul(matrix A,int k)
{
matrix B;
for(int i=1;i<=n+2;i++)B.mat[i][i]=1;
while(k>=1)
{
if(k&1)B=mul(B,A);
A=mul(A,A);
k=k/2;
}
return B;
}
void print(matrix A)
{
cout<<"matrix A"<<endl;
for(int i=1;i<=n+2;i++)
{
for(int j=1;j<=n+2;j++)
{
cout<<A.mat[i][j]<<" ";
}
cout<<endl;
}
}
int main()
{
int m;
while(~scanf("%d%d",&n,&m))
{
matrix A,B;
A.mat[1][1]=23;
for(int i=1;i<=n;i++)
{
scanf("%d",&A.mat[i+1][1]);
}
A.mat[n+2][1]=3;
for(int i=1;i<=n+1;i++)B.mat[i][1]=10;
for(int i=1;i<=n+2;i++)B.mat[i][n+2]=1;
for(int i=2;i<=n+1;i++)
{
for(int j=2;j<=i;j++)B.mat[i][j]=1;
}
// print(A);
// print(B);
B=powmul(B,m);
A=mul(B,A);
// print(A);
cout<<A.mat[n+1][1]<<endl;
}
return 0;
}
hdu-5015-233 Matrix-矩阵的更多相关文章
- 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 --矩阵快速幂
题意:给出矩阵的第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(网络赛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(杨辉三角/前缀+矩阵快速幂)
233 Matrix In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23 ...
- hdu 5015 233 Matrix(构造矩阵)
http://acm.hdu.edu.cn/showproblem.php?pid=5015 由于是个二维的递推式,当时没有想到能够这样构造矩阵.从列上看,当前这一列都是由前一列递推得到.依据这一点来 ...
- HDU 5015 233 Matrix
题意:给定一个矩阵的第0列的第1到n个数,第一行第1个数开始每个数分别为233, 2333........,求第n行的第m个数. 分析: 其实也没那么难,自己想了半天还没往对的方向想,m最大1e9,应 ...
- HDU5015 233 Matrix(矩阵高速幂)
HDU5015 233 Matrix(矩阵高速幂) 题目链接 题目大意: 给出n∗m矩阵,给出第一行a01, a02, a03 ...a0m (各自是233, 2333, 23333...), 再给定 ...
- 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 ...
随机推荐
- 快乐的Linux命令行
ls - 列出目录内容 -a 列出所有文件 -d 指定目录信息 -F 为目录增加/标识 -h 增强可读性 -l 列模式显示 -r 反序显示 -S 按照大小排序 -t 按照修改时间排序 file - 确 ...
- POJ 1815 Friendship(字典序最小的最小割)
Friendship Time Limit: 2000MS Memory Limit: 20000K Total Submissions: 10744 Accepted: 2984 Descr ...
- [CQOI2016][bzoj4519] 不同的最小割 [最小割树]
题面 传送门 思路 首先我们明确一点:这道题不是让你把$n^2$个最小割跑一遍[废话] 但是最小割过程是必要的,因为最小割并没有别的效率更高的算法(Stoer-Wagner之类的?) 那我们就要尽量找 ...
- BZOJ4540 [Hnoi2016]序列 【莫队 + ST表 + 单调栈】
题目 给定长度为n的序列:a1,a2,-,an,记为a[1:n].类似地,a[l:r](1≤l≤r≤N)是指序列:al,al+1,-,ar- 1,ar.若1≤l≤s≤t≤r≤n,则称a[s:t]是a[ ...
- POJ1385 Lifting the Stone
There are many secret openings in the floor which are covered by a big heavy stone. When the stone i ...
- 【HDOJ5528】Count a * b(积性函数)
题意:设f(i)为0<=x,y<=i-1且xy%i=0的(x,y)对数,g(i)为sigma f(j) [i%j==0] 给定n,求g(n),答案对2^64取模 T<=2e4,n&l ...
- DataGrid关键字变色
原文发布时间为:2009-05-01 -- 来源于本人的百度文章 [由搬家工具导入] private void DataGrid1_ItemDataBound(object sender, ...
- 【全局变量】mysql查看全局变量以及设置全局变量的值
1.查看mysql的所有全局变量的值 SHOW GLOBAL VARIABLES 或者 SHOW VARIABLES mysql有很多全局变量,包括系统的一些基本信息,以及mysql的一些基本配置都可 ...
- duilib入门简明教程 -- 自绘标题栏(5) (转)
原文转自 http://www.cnblogs.com/Alberl/p/3343667.html 如果大家有做过标题栏的自绘,肯定会感慨各种不容易,并且现有的一些资料虽然完美的实现了 ...
- [原创] 树莓派个人实测 Q&A(最新修改使用windows连接远程桌面)
原文出处:http://www.eeboard.com/bbs/thread-5191-1-1.html 这篇帖子我打算用Q&A的方式来编写,这样大家更容易一目了然的看明整个帖子的内容,层次分 ...