233 Matrix

Time Limit: 10000/5000 MS (Java/Others)    Memory
Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1399    Accepted Submission(s): 826

Problem Description
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233333 ... in the same meaning. And here is the question: Suppose we have a matrix called 233 matrix. In the first line, it would be 233, 2333, 23333... (it means
a0,1 = 233,a0,2 = 2333,a0,3 = 23333...) Besides, in 233 matrix, we got ai,j = ai-1,j +ai,j-1( i,j ≠ 0). Now you have known a1,0,a2,0,...,an,0, could you tell
me an,m in the 233 matrix?
 
Input
There are multiple test cases. Please process till EOF.



For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 109). The second line contains n integers, a1,0,a2,0,...,an,0(0 ≤ ai,0 < 231).
 
Output
For each case, output an,m mod 10000007.
 
Sample Input
1 1
1
2 2
0 0
3 7
23 47 16
 
Sample Output
234
2799
72937
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#define LL long long
using namespace std;
const long long MAXN = 15;
const long long mod = 10000007;
struct Matrix
{
long long mat[MAXN][MAXN], n;
Matrix(){memset(mat, 0, sizeof(mat));}
Matrix operator * (Matrix & rhs)
{
Matrix res; res.n = n;
for(long long i=1;i<=n;i++)
{
for(long long j=1;j<=n;j++)
{
for(long long k=1;k<=n;k++)
{
(res.mat[i][j] += (mat[i][k] * rhs.mat[k][j]) % mod) %= mod;
}
}
}
return res;
}
};
Matrix pow_mod(Matrix a, long long b)
{
Matrix res; res.n = a.n;
for(long long i=1;i<=a.n;i++) res.mat[i][i] = 1;
while(b)
{
if(b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
long long a[MAXN], n, m;
int main()
{
while(scanf("%I64d%I64d", &n, &m)!=EOF)
{
for(long long i=1;i<=n;i++) scanf("%I64d", &a[i]);
Matrix ans; ans.n = n + 2;
for(long long i=1;i<=n + 1;i++)
{
ans.mat[i][1] = 10;
for(long long j=2;j<=i;j++)
{
ans.mat[i][j] = 1;
}
}
for(long long i=1;i<=n+1;i++) ans.mat[n+2][i] = 0;
for(long long i=1;i<=n+2;i++) ans.mat[i][n+2] = 1;
ans = pow_mod(ans, m);
/* for(long long i=1;i<=n+2;i++)
{
for(long long j=1;j<=n+2;j++)
cout << ans.mat[i][j] << ' ';
cout <<endl;
}*/
a[0] = 23, a[n+1] = 3;
long long rs = 0;
for(long long i=1;i<=n+2;i++) (rs += a[i-1] * ans.mat[n+1][i]) %= mod;
printf("%I64d\n", rs);
}
return 0;
}

HDU 5015 233Matrix (构造矩阵)的更多相关文章

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

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

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

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

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

  4. hdu 5015 233矩阵快速幂

    http://acm.hdu.edu.cn/showproblem.php?pid=5015 需要构造一个 n+2 维的矩阵. 就是要增加一维去维护2333这样的序列. 可以发现 2333 = 233 ...

  5. HDU 3306 Another kind of Fibonacci ---构造矩阵***

    Another kind of Fibonacci Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  6. HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...

  7. HDU 5667 构造矩阵快速幂

    HDU 5667 构造矩阵快速幂 题目描述 解析 我们根据递推公式 设 则可得到Q的指数关系式 求Q构造矩阵 同时有公式 其中φ为欧拉函数,且当p为质数时有 代码 #include <cstdi ...

  8. Number Sequence(HDU 1005 构造矩阵 )

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. hdu 5015 矩阵快速幂(可用作模板)

    转载:http://blog.csdn.net/wdcjdtc/article/details/39318847 之前各种犯傻 推了好久这个东西.. 后来灵关一闪  就搞定了.. 矩阵的题目,就是构造 ...

随机推荐

  1. jQuery中$this和$(this)的区别

    要写一个点击弹窗任意地方,关闭弹窗.点击事件写标签在元素上 onclick =  closepop(this),这时候很容易搞不清楚怎么去获取当前元素 function closepop(e){ va ...

  2. 下载github项目

    两种方法:通过https或者ssh地址 找一个放置项目的文件夹,右键git bash here 输入 $ git clone https://项目地址 通过https 项目地址可以直接复制网页地址,或 ...

  3. servlet——web应用中路径问题

    target.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html ...

  4. 什么是vuejs之重新认识vuejs

    什么是vuejs? 1.它是一个轻量级的mvvm框架 2.数据驱动+组件化的前端开发 3.github超过25k+的stat数,社区完善 4.vuejs更轻量,gzip后大小只有20k+ 5.vuej ...

  5. How a stack frame works 栈帧的要素与构建步骤

    http://en.citizendium.org/wiki/Stack_frame To use a stack frame, a thread keeps two pointers, often ...

  6. JAVA程序员面试笔试宝典3

    1.什么是线程?它与进程有什么区别?为什么要使用多线程 线程是指程序在执行过程中,能够执行程序代码的一个执行单元.进程是指一段正在执行的程序. 使用多线程可以减少程序的相应时间 与进程相比,线程的创建 ...

  7. 17Web应用乱码问题

    Web应用乱码问题 Web应用乱码问题 简介 每个国家(或区域)都规定了本国家(或地区)计算机信息交换用的字符编码集,如美国的扩展ASCII码, 中国的GB2312-80,日本的JIS 等,作为该国家 ...

  8. Linux之修改主机名(永久生效)

    Linux系统安装好后,都会有默认的主机名,这里以CentOS系统为例,默认的主机名为localhost.localdomain,为了便于使用,我们常常需要修改主机名,下面演示的是永久更改主机名的方法 ...

  9. DAS、NAS、SAN、iSCSI 存储方案概述

    (转自https://blog.csdn.net/tianlesoftware/article/details/6201346) 目前服务器所使用的专业存储方案有DAS.NAS.SAN.iSCSI几种 ...

  10. 回车符号 ‘\r’ 的实际应用

    由于最近开始研究自动化测试 首先是自动定时去下载安装包,需要实时显示进度. 于是了解了进度条相关的方法. 作下记录. 区别 \r 表示将光标的位置回退到本行的开头位置 \n 表示光标从下一行的开头位置 ...