[HDU5015]233 Matrix
[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, 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的更多相关文章
- HDU5015 233 Matrix(矩阵高速幂)
HDU5015 233 Matrix(矩阵高速幂) 题目链接 题目大意: 给出n∗m矩阵,给出第一行a01, a02, a03 ...a0m (各自是233, 2333, 23333...), 再给定 ...
- HDU5015 233 Matrix —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-5015 233 Matrix Time Limit: 10000/5000 MS (Java/Others) Memor ...
- ACM学习历程——HDU5015 233 Matrix(矩阵快速幂)(2014陕西网赛)
Description In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 2 ...
- 233 Matrix(hdu5015 矩阵)
233 Matrix Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- Spring-1-I 233 Matrix(HDU 5015)解题报告及测试数据
233 Matrix Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descript ...
- 233 Matrix(矩阵快速幂+思维)
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
- HDU - 5015 233 Matrix(杨辉三角/前缀+矩阵快速幂)
233 Matrix In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23 ...
- HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂
先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html http://www.cppblog.com/acronix/archive/20 ...
- hdu 5015 233 Matrix (矩阵高速幂)
233 Matrix Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
随机推荐
- Linux下硬盘安装Windows系统。
注意:本方法安装后会把Linux系统损坏,方法适用于完全不再需要Linux系统. 本方法在ubuntu 14.04,centos 6.5,debian 8测试成功. 安装方法是通过grub2引导Win ...
- [BZOJ2659][WC2012]算不出的算式(几何)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2659 分析:很巧的想法,原式的值就是y=q/p x这条直线的下面和左边的点的个数.处理 ...
- 第四章:javascript: 栈
列表是一种最自然的数据组织方式.上一章已经介绍如何使用List类将数据组织成一个列表.如果数据存储的顺序不重要.也不必对数据进行查找,那么列表就是一种再好不过的数据结构.对于其它的一些应用,列表就显得 ...
- WPF MenuItem 四种角色分析
Menu Menu的样式很简单,就是顶部的那个框,如下图 而其中的文字“文件”“图形”...是属于MenuItem的,要灵活使用MenuItem,就需要了解MenuItem.Role的作用 T ...
- mysqldump使用方法
1.mysqldump的几种常用方法: (1)导出整个数据库(包括数据库中的数据) mysqldump -u username -p dbname > dbname.sql (2)导出数据库结构 ...
- 【转】变量的声明和定义,从C到编译原理到C++,再到Java
基础学了太久,时间一长有些东西就可能记得不太清楚,俗话说得好,"好记性不如烂笔头",所以把基础中的基础-变量的声明和定义,从C到编译原理到C++,再到Java用烂笔头记录下来 最早 ...
- 【HDU 5387】Clock
题 Description Give a time.(hh:mm:ss),you should answer the angle between any two of the minute.hour. ...
- Blog Explanation
有疑问或blog中说明错误的欢迎评论或联系QQ:30056882,邮箱BLADEVIL@outlook.com.本人水平不高,欢迎讨论问题. blog中所有随笔均为原创,转载请注明来源. (已退役.)
- POJ1703Find them, Catch them
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37722 Accepted: ...
- ASP.NET MVC 中将数据从View传递到控制器中的三种方法(表单数据绑定)
http://www.cnblogs.com/zyqgold/archive/2010/11/22/1884779.html 在ASP.NET MVC框架中,将视图中的数据传递到控制器中,主要通过发送 ...