hdu 5015 233 Matrix (矩阵高速幂)

233 Matrix

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

Total Submission(s): 749    Accepted Submission(s): 453

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

Hint


思路:

第一列元素为:

0

a1

a2

a3

a4

转化为:

23

a1

a2

a3

a4

3

则第二列为:

23*10+3

23*10+3+a1

23*10+3+a1+a2

23*10+3+a1+a2+a3

23*10+3+a1+a2+a3+a4

3

依据前后两列的递推关系,有等式可得矩阵A的元素为:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTcyMTQ0MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" >

#include"iostream"
#include"stdio.h"
#include"string.h"
#include"algorithm"
#include"queue"
#include"vector"
using namespace std;
#define N 15
#define LL __int64
const int mod=10000007;
int n;
int b[N];
struct Mat
{
    LL mat[N][N];
}a,ans;
Mat operator*(Mat a,Mat b)
{
    int i,j,k;
    Mat c;
    memset(c.mat,0,sizeof(c.mat));
    for(i=0; i<=n+1; i++)
    {
        for(j=0; j<=n+1; j++)
        {
            c.mat[i][j]=0;
            for(k=0; k<=n+1; k++)
            {
                if(a.mat[i][k]&&b.mat[k][j])
                {
                    c.mat[i][j]+=a.mat[i][k]*b.mat[k][j];
                    c.mat[i][j]%=mod;
                }
            }
        }
    }
    return c;
}
void mult(int k)
{
    int i;
    memset(ans.mat,0,sizeof(ans.mat));
    for(i=0;i<=n+1;i++)
        ans.mat[i][i]=1;
    while(k)
    {
        if(k&1)
            ans=ans*a;
        k>>=1;
        a=a*a;
    }
}
void inti()
{
    int i,j;
    b[0]=23;
    b[n+1]=3;
    for(i=1; i<=n; i++)
        scanf("%d",&b[i]);
    memset(a.mat,0,sizeof(a.mat));
    for(i=0; i<=n; i++)
    {
        a.mat[i][0]=10;
        a.mat[i][n+1]=1;
    }
    a.mat[n+1][n+1]=1;
    for(i=1; i<n+1; i++)
    {
        for(j=1; j<=i; j++)
        {
            a.mat[i][j]=1;
        }
    }
}
int main()
{
    int i,m;
    while(scanf("%d%d",&n,&m)!=-1)
    {
        inti();
        mult(m);
        LL s=0;
        for(i=0;i<=n+1;i++)
            s=(s+(ans.mat[n][i]*b[i])%mod)%mod;
        printf("%I64d\n",s);
    }
    return 0;
}
时间: 2024-10-03 14:14:55

hdu 5015 233 Matrix (矩阵高速幂)的相关文章

HDU 5015 233 Matrix(矩阵快速幂)

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

hdu 5015 233 Matrix (矩阵快速幂)

题意: 有一种矩阵,它的第一行是这样一些数:a  0,0 = 0, a 0,1 = 233,a 0,2 = 2333,a 0,3 = 23333... 除此之外,在这个矩阵里, 我们有 a i,j = a i-1,j +a i,j-1( i,j ≠ 0).现在给你 a 1,0,a 2,0,...,a n,0, 你能告诉我a n,m 是多少吗? n,m(n ≤ 10,m ≤ 10 9)输出 a n,m mod 10000007. 思路:首先我们观察n和m的取值范围,会发现n非常小而m却非常大,如果

HDU - 5015 233 Matrix (矩阵构造)

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

HDU 5015 233 Matrix(西安网络赛I题)

HDU 5015 233 Matrix 题目链接 思路:矩阵快速幂,观察没一列,第一个和为左边加最上面,第二个可以拆为左边2个加最上面,第三个可以拆为为左边3个加最上面,这样其实只要把每一列和每一列右边那列的233构造出一个矩阵,进行矩阵快速幂即可 代码: #include <cstdio> #include <cstring> typedef long long ll; const int N = 15; const int MOD = 10000007; int n, m; s

HDU 1575 Tr A(矩阵高速幂)

题目地址:HDU 1575 矩阵高速幂裸题. 初学矩阵高速幂.曾经学过高速幂.今天一看矩阵高速幂,原来其原理是一样的,这就好办多了.都是利用二分的思想不断的乘.仅仅只是把数字变成了矩阵而已. 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #i

[矩阵快速幂] hdu 5015 233 Matrix

之前各种犯傻 推了好久这个东西.. 后来灵关一闪  就搞定了.. 矩阵的题目,就是构造矩阵比较难想! 题意:给出一个矩阵的第一列和第一行(下标从0开始),(0,0)位置为0, 第一行为,233,2333,23333...一次加个3, 第一列为输入的n个数. 然后从(1,1)位置开始,等于上面的数加左边的数,问(n+1,m+1)的数是多少,也就是右下角的数 思路: 把矩阵画出来: |   0     233   2333  | |  b0     b1     b2     | |  c0    

hdu 5015 233 Matrix (矩阵快速幂)

233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 749    Accepted Submission(s): 453 Problem Description In our daily life we often use 233 to express our feelings. Actually, we may s

hdu 5015 233 Matrix(西安网络赛1009)【构造矩阵】

说起这题简直醉了..当时愣是没想到该怎么做,搞了好久,虽然有想过构造矩阵,但是没仔细想下去. 此题构造两个矩阵,假设a[]数组为题目给出的数据,最多有10个元素,我们可以构造一个矩阵A: a={a[1],a[2],a[3],...a[n],23,3}  大小为1*(n+2) 要得到题目需要的计算结果,那么在构造一个矩阵B,大小为(n+2)*(n+2):(假设n=3) b=   1    1    1    0    0 0    1    1    0    0 0    0    1    0

233 Matrix 矩阵快速幂

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