# 233 Matrix

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2819    Accepted Submission(s): 1621

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 112 20 03 723 47 16

Sample Output
234279972937
Hint

Source

AC的C++语言程序如下：

/* HDU5015 233 Matrix */

#include <iostream>
#include <string.h>
#include <stdio.h>

//#define DEBUG

using namespace std;

typedef long long LL;

const int MOD = 10000007;
const int N = 10;

int n, m;

struct Matrix
{
LL m[N + 3][N + 3];
Matrix()
{
memset(m, 0, sizeof(m));
}
};

Matrix Matrix_Mul(Matrix a, Matrix b)
{
Matrix c;

for(int i=1; i<=n+2; i++)
for(int j=1; j<=n+2; j++)
for(int k=1; k<=n+2; k++)
c.m[i][j] = (c.m[i][j] + a.m[i][k] * b.m[k][j]) % MOD;

return c;
}

// 矩阵模幂
Matrix Matrix_Powmul(Matrix a, int m)
{
Matrix c;

for(int i=1; i<=n+2; i++)
c.m[i][i] = 1;
while(m) {
if(m & 1)
c = Matrix_Mul(c, a);
a = Matrix_Mul(a, a);
m >>= 1;
}

return c;
}

#ifdef DEBUG
void Matrix_Print(Matrix a, const char *name)
{
printf("matrix %s\n", name);
for(int i=1; i<=n+2; i++) {
for(int j=1; j<=n+2; j++)
printf("%lld ", a.m[i][j]);
printf("\n");
}
}
#endif

int main()
{
while(~scanf("%d%d", &n, &m)) {
Matrix a, b;

a.m[1][1] = 23;
for(int i=1; i<=n; i++)
scanf("%lld", &a.m[i + 1][1]);
a.m[n + 2][1] = 3;

for(int i=1; i<=n+1; i++)
b.m[i][1] = 10;
for(int i=1; i<=n+2; i++)
b.m[i][n + 2] = 1;
for(int i=2; i<=n+1; i++)
for(int j=2; j<=i; j++)
b.m[i][j] = 1;

#ifdef DEBUG
Matrix_Print(a, "a");
Matrix_Print(b, "b");
#endif

b = Matrix_Powmul(b, m);
a = Matrix_Mul(b, a);

#ifdef DEBUG
Matrix_Print(a, "a");
#endif

printf("%lld\n", a.m[n + 1][1]);
}

return 0;
}


#### hdu 5015 233 Matrix(最快的搞法)

2014-09-14 22:03:35

#### hdu-5015-233 Matrix-矩阵

2014-09-17 15:54:51

#### hdu 5015 233 Matrix （矩阵快速幂）

2014-09-19 18:17:14

#### 【hdu5015】233 Matrix——矩阵快速幂

2016-02-26 16:39:03

#### HDU5015 233 Matrix(矩阵快速幂)

2014-09-17 10:51:44

#### hdu5015 233 Matrix（矩阵快速幂）

2015-08-24 21:02:50

#### hdu5015 233 Matrix 矩阵快速幂

2014-09-16 21:05:41

#### hdu5015——233 Matrix（矩阵快速幂）

2017-04-18 13:05:00

#### HDU5015 - 233 Matrix - 思维+矩阵快速幂

2017-03-04 19:34:57

#### 解题报告：HDU5015 233 Matrix 矩阵快速幂

2016-08-22 15:46:04