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

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. linux下编译libmysqlclient, 安装mysql-server mysql-client

    cmake . -DCMAKE_INSTALL_PREFIX=/home/zhangyawei/server/depends make make install 安装 mysql-server mys ...

  2. [NOI2008][bzoj1061] 志愿者招募 [费用流+巧妙的建图]

    题面 传送门 思路 引入:网络流? 看到这道题,第一想法是用一个dp来完成决策 但是,显然这道题的数据并不允许我们进行dp,尤其是有10000种志愿者的情况下 那么我们就要想别的办法来解决: 贪心?这 ...

  3. java根据开始时间结束时间计算中间间隔日期

    public static void main(String[] args) throws Exception { String beginDate = "2016-07-16"; ...

  4. linux磁盘挂载流程

    参考 [https://www.jianshu.com/p/ea57fb7834f2]

  5. nodeJS学习(5) --- sublime Text3 安装使用

    本节对对工具 sublime Text3 的安装进行简介. 主要参考网址:http://blog.csdn.net/sam976/article/details/52076271   http://w ...

  6. NodeJS学习(1)--- 安装配置介绍

    Node.js 安装配置 本章节我们将向大家介绍在window和Linux上安装Node.js的方法. 本安装教程以Node.js v6.10.1 LTS(长期支持版本)版本为例. Node.js安装 ...

  7. 粟粟的书架(bzoj 1926)

    Description 幸福幼儿园 B29 班的粟粟是一个聪明机灵.乖巧可爱的小朋友,她的爱好是画画和读书,尤其喜欢 Thomas H. Co rmen 的文章.粟粟家中有一个 R行C 列的巨型书架, ...

  8. BZOJ【1639】: [Usaco2007 Mar]Monthly Expense 月度开支

    1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 700  Solved: ...

  9. WIN8.1安装 .net framework 3.5

    1.虚拟光驱加载安装镜像 2.以管理员权限运行cmd 3.输入以下命令: dism.exe /online /enable-feature /featurename:NetFX3 /Source:X: ...

  10. Day 1 MySQL数据库

    MySQL数据库_1 一.概述 1.数据(DATA) 描述事物的符号记录称为数据,描述事物的符号既可以是数字,也可以是文字.图片,图像.声音.语言等,数据由多种表现形式,它们都可以经过数字化后存入计算 ...