[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. Bootstrap系列 -- 31.嵌套分组

    我们常把下拉菜单和普通的按钮组排列在一起,实现类似于导航菜单的效果.使用的时候,只需要把当初制作下拉菜单的“dropdown”的容器换成“btn-group”,并且和普通的按钮放在同一级 <di ...

  2. php发送get、post请求的6种方法简明总结

    方法1: 用file_get_contents 以get方式获取内容: ? 1 2 3 4 5 <?php $url='http://www.jb51.net/'; $html = file_g ...

  3. 每天一个linux命令(38):vmstat命令

    vmstat 是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存.进程.CPU活动进行监控.他是对系统的整体 情况进行统计,不足之处是无法对某个进程进 ...

  4. Html巩固

    1.html元素都支持全局属性(通用的属性)和事件属性.     a标签:定义一个超文本链接,链接到另一个超文本文件的! button:定义一个点击按钮,按钮是出发当前页面的事件.

  5. oracle-2中commit 详解

    博文转自:http://blog.csdn.net/hzhsan/article/details/9719307 它执行的时候,你不会有什么感觉.commit在数据库编程的时候很常用,当你执行DML操 ...

  6. C#中async/await中的异常处理

    在同步编程中,一旦出现错误就会抛出异常,我们可以使用try-catch来捕捉异常,而未被捕获的异常则会不断向上传递,形成一个简单而统一的错误处理机制.不过对于异步编程来说,异常处理一直是件麻烦的事情, ...

  7. grunt使用watch和livereload的Gruntfile.js的配置

    周末在家看angularJS, 用grunt的livereload的自动刷新, 搞了大半天, 现在把配置贴出来, 免得以后忘记了, 只要按照配置一步步弄是没有问题的; 开始的准备的环境安装是: (1) ...

  8. Java原来如此-比较器(Comparable、Comparator)

    有时候需要对Collection或者不为单一数字的Array进行比较,有两种方法,1是实现Comparable接口,2是实现Comparator接口. 1.ComParable接口 Comparabl ...

  9. Oracle定时执行存储过程

    首先查看 SQL> show parameter job NAME                                 TYPE        VALUE-------------- ...

  10. 洛谷P1908 求逆序对 [归并排序]

    题目描述 猫猫TOM和小老鼠JERRY最近又较量上了,但是毕竟都是成年人,他们已经不喜欢再玩那种你追我赶的游 戏,现在他们喜欢玩统计.最近,TOM老猫查阅到一个人类称之为“逆序对”的东西,这东西是这样 ...