非常显然矩阵的第一列为:

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-矩阵的更多相关文章

  1. HDU - 5015 233 Matrix (矩阵快速幂)

    In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...

  2. 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] ...

  3. HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂

    先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html http://www.cppblog.com/acronix/archive/20 ...

  4. hdu 5015 233 Matrix (矩阵高速幂)

    233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tota ...

  5. HDU - 5015 233 Matrix(杨辉三角/前缀+矩阵快速幂)

    233 Matrix In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23 ...

  6. hdu 5015 233 Matrix(构造矩阵)

    http://acm.hdu.edu.cn/showproblem.php?pid=5015 由于是个二维的递推式,当时没有想到能够这样构造矩阵.从列上看,当前这一列都是由前一列递推得到.依据这一点来 ...

  7. HDU 5015 233 Matrix

    题意:给定一个矩阵的第0列的第1到n个数,第一行第1个数开始每个数分别为233, 2333........,求第n行的第m个数. 分析: 其实也没那么难,自己想了半天还没往对的方向想,m最大1e9,应 ...

  8. HDU5015 233 Matrix(矩阵高速幂)

    HDU5015 233 Matrix(矩阵高速幂) 题目链接 题目大意: 给出n∗m矩阵,给出第一行a01, a02, a03 ...a0m (各自是233, 2333, 23333...), 再给定 ...

  9. 233 Matrix(矩阵快速幂+思维)

    In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...

  10. HDU5015 233 Matrix —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-5015 233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memor ...

随机推荐

  1. Canvas与Image互相转换示例以及利用该技术实现微信长按自动识别二维码功能

    现在扫描二维码已经很普遍,微信扫一扫即可,但是如果二维码是在自己的手机上呢?那就要用到微信里的一个功能了,手指长按二维码,会弹出自动识别的选项,点确定就可以看到二维码的内容了.那么怎么通过前端实现这个 ...

  2. JAVA会员生日和密码

    import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import ja ...

  3. https总结

    http与https不能互相发送ajax请求,因为跨域了. http页面请求https静态资源可以,但是https请求http静态资源会提示错误. 总之,宽松的可以请求严格的,但是严格的不能请求宽松的 ...

  4. Java面试题之如何防止重复下单问题?

    在电商环境下,如何防止重复下单这种问题,很常见,并且解决方案有很多种,我经过百度,并且加入我的理解唠嗑几句: 流程: ①当进入商品详情页时,去生成一个全局唯一ID(可用雪花算法): ②将这个全局唯一I ...

  5. vue-router 页面切换后保持在页面顶部而不是保持原先的滚动位置的办法

    vue-router有提供一个方法scrollBehavior,它可以使切换到新路由时,想要页面滚到顶部,或者是保持原先的滚动位置,就像重新加载页面那样. 这个功能只在 HTML5 history 模 ...

  6. 用ashx还是aspx写ajax响应

    原文发布时间为:2009-11-16 -- 来源于本人的百度文章 [由搬家工具导入] 结论: 用ashx 都能写AJAX的响应,在那种情况下,调用哪种比较好? 有很大的影响吗? ---------回复 ...

  7. [转]在Storyboard中使用自定义的segue类型

    转自:http://my.oschina.net/u/728866/blog/92709 我们知道segue共有三种类型:push.modal以及custom.如下图:   很明显,这三种类型的作用分 ...

  8. Scrapy学习-23-分布式爬虫

    scrapy-redis分布式爬虫 分布式需要解决的问题 request队列集中管理 去重集中管理 存储管理   使用scrapy-redis实现分布式爬虫 github开源项目: https://g ...

  9. ios开发某个页面横不过来屏幕的时候

    某一个页面需要横屏,其他的页面任然保持竖屏需要以下关键的几个步骤: 1.修改系统代理方法的返回值 -(UIInterfaceOrientationMask)application:(UIApplica ...

  10. Algorithm | Sort

    Bubble sort Bubble sort, sometimes incorrectly referred to as sinking sort, is a simple sorting algo ...