58人阅读 评论(0)

# 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;
}


个人资料
等级：
访问量： 108万+
积分： 2万+
排名： 353
文章分类
博客专栏
 ACM题解 文章：590篇 阅读：403999 趣味程序 文章：40篇 阅读：34221 大学计算机读本 文章：14篇 阅读：19815 基础程序 文章：15篇 阅读：14006 CCF认证题解 文章：45篇 阅读：142030 Project Euler问题程序解 文章：39篇 阅读：16001 NOIP赛题解 文章：19篇 阅读：9487
最新评论