[HDU5015]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... (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?

输入

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

输出

For each case, output an,m mod 10000007

输入示例


输出示例


数据规模及约定

见“输入

题解

懒得翻译了,不难看懂(毕竟我也是英语渣)。

发现 n 很小,但是 m 必须在外面套一个 log,所以应该想到矩阵快速幂优化递推式。

第 0 行的 233 们可以有递推式 f(i) = f(i-1) * 10 + 3,其中 f(1) = 233.

第 1 行的则有 g(i) = g(i-1) + f(i),其中g(1) = f(1) + a1,0.(a 为题目描述中的矩阵)

第 2 行的则有 h(i) = h(i-1) + g(i),其中h(1) = g(1) + a2,0.

有规律了吧。。。

#include <iostream>
using namespace std; #define maxn 15
#define MOD 10000007
#define LL long long
struct Matrix {
int n, m, A[maxn][maxn];
Matrix operator * (const Matrix& t) const {
Matrix ans; ans.n = t.n; ans.m = m;
for(int i = 1; i <= ans.n; i++)
for(int j = 1; j <= ans.m; j++) {
ans.A[i][j] = 0;
for(int k = 1; k <= n; k++) {
ans.A[i][j] += (int)(((LL)t.A[i][k] * A[k][j]) % MOD);
if(ans.A[i][j] > MOD) ans.A[i][j] -= MOD;
}
}
return ans;
}
} base, sol; Matrix Pow(Matrix a, int x) {
Matrix t = a, ans = a; x--;
while(x) {
if(x & 1) ans = ans * t;
x >>= 1; t = t * t;
}
return ans;
} int A[maxn];
int main() {
int n, m;
while(scanf("%d%d", &n, &m) == 2) {
for(int i = 1; i <= n; i++) {
scanf("%d", &A[i]);
if(A[i] > MOD) A[i] %= MOD;
}
base.n = n + 2; base.m = 1;
sol.n = sol.m = n + 2;
base.A[n+2][1] = 1;
int sum = 233;
for(int i = n + 1; i; i--) {
base.A[i][1] = sum;
sum += A[n-i+2];
if(sum > MOD) sum -= MOD;
}
for(int i = 1; i <= n + 1; i++) {
for(int j = 1; j <= n; j++) if(j < i) sol.A[i][j] = 0;
else sol.A[i][j] = 1;
sol.A[i][n+1] = 10; sol.A[i][n+2] = 3;
}
for(int i = 1; i <= n + 1; i++) sol.A[n+2][i] = 0; sol.A[n+2][n+2] = 1;
if(m > 1) base = base * Pow(sol, m-1);
printf("%d\n", base.A[1][1]);
} return 0;
}

[HDU5015]233 Matrix的更多相关文章

  1. HDU5015 233 Matrix(矩阵高速幂)

    HDU5015 233 Matrix(矩阵高速幂) 题目链接 题目大意: 给出n∗m矩阵,给出第一行a01, a02, a03 ...a0m (各自是233, 2333, 23333...), 再给定 ...

  2. HDU5015 233 Matrix —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-5015 233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memor ...

  3. ACM学习历程——HDU5015 233 Matrix(矩阵快速幂)(2014陕西网赛)

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

  4. 233 Matrix(hdu5015 矩阵)

    233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  5. Spring-1-I 233 Matrix(HDU 5015)解题报告及测试数据

    233 Matrix Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Descript ...

  6. 233 Matrix(矩阵快速幂+思维)

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

  7. HDU - 5015 233 Matrix(杨辉三角/前缀+矩阵快速幂)

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

  8. HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂

    先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html http://www.cppblog.com/acronix/archive/20 ...

  9. hdu 5015 233 Matrix (矩阵高速幂)

    233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tota ...

随机推荐

  1. js监听键盘回车

    //监听回车 $(document).keydown(function(e) { ) { $("#btnLogin").click(); } }) //input绑定回车 $('# ...

  2. jTemplate —— 基于jQuery的javascript前台模版引擎

    reference: http://blog.csdn.net/lexinquan/article/details/6674102     http://blog.csdn.net/kuyuyingz ...

  3. GridView的常规用法

    GridView控件在Asp.net中相当常用,以下是控件的解释,有些是常用的,有些是偶尔用到的,查找.使用.记录,仅此而已.(最后附带DropDownList控件) ASP.NET中GridView ...

  4. 第六章:javascript:字典

    字典是一种以键-值对应形式存储的数据结构,就像电话薄里的名字和电话号码一样.只要找一个电话,查找名字,名字找到后,电话号码也就找到了.这里的键值是你用来查找的东西,值就是要查的到的结果. javasc ...

  5. Linux_日志信息

    一.httpd日志:/var/log/httpd1.软件位置:whereis httpd2.配置文件位置:/etc/httpd/conf/httpd.conf 二.mysql日志:/var/log 查 ...

  6. 虚拟机 vlan trunk 特性

    1. 功能 1)允许不同vlan的network下的虚拟机之间通信.一般情况下,虚拟机只能在相同vlan的网络下通信. 2)允许虚拟机发送vlan报文. 2. 组网图 虚拟机出来的tap设备连接到tb ...

  7. hdu1853 km算法

    //hdu1853 #include<stdio.h> #include<string.h> #define INF 99999999 ][],pr[],pl[],visr[] ...

  8. Android中的Uri.parse()

    1,调web浏览器 Uri myBlogUri = Uri.parse("http://www.baidu.com"); returnIt = new Intent(Intent. ...

  9. sqlserver字段类型详解

    抄了一篇不错的数据库类型,来自:http://www.cnblogs.com/andy_tigger/archive/2011/08/21/2147745.html bit 整型 bit数据类型是整型 ...

  10. TCP/IP详解 学习二

    链路层: 在 T C P / I P协议族中,链路层主要有三个目的:(1)为 I P模块发送和接收 I P数据报:( 2)为 A R P模块发送 A R P请求和接收 A R P应答:( 3)为 R ...