[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 ...
随机推荐
- QRadioButton分组且无边框的简单实现
最近在用QT+VS2008做一个项目,涉及到一个综合测评表,说白了有点像问卷调查——很多题目每题若干个选项. 初始时打算用下拉框,每个框中填入所有选项,但后来一琢磨这种方式不够直观与人性化,增添了一步 ...
- JAVA中的NIO(二)
一.内存文件映射 内存文件映射允许我们创建和修改那些因为太大而不能放入内存中的文件.有了内存文件映射,我们就可以假定整个文件都在内存中,而且可以完全把文件当作数组来访问. package com.dy ...
- Boostrap响应式与非响应式
非响应式布局 在使用非响应式布局时,在<head>标签中需要加入一下内容,其中最主要的是non-responsive.css文件 <head> <meta http-eq ...
- 编写兼容性JS代码
前文介绍了: 1 DOM四个常用的方法 2 使用DOM核心方法完成属性填充 本篇主要介绍在JS中需要注意的几个地方,另外为了减小html与javascript的耦合使用java进行onclick方法编 ...
- 阿里百川IMSDK--自定义群聊界面
// 获取群对象 YWTribe *tribe = [self.tribesArray objectAtIndex:indexPath.row]; // 发起群聊 UIViewController * ...
- DNA repair问题
问题:Biologists finally invent techniques of repairing DNA that contains segments causing kinds of inh ...
- HDU-1698 JUST A HOOK 线段树
最近刚学线段树,做了些经典题目来练手 Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- 【bzoj1502】 NOI2005—月下柠檬树
http://www.lydsy.com/JudgeOnline/problem.php?id=1502 (题目链接) 今天考试题,从来没写过圆的面积之类的东西..GG 题意 一颗树由n个圆台组成,现 ...
- Azure怎么使用ftp登录
1.下载配置文件 2.拷贝FTP的地址 3.查看配置文件里面的用户名和密码 4.登录
- POJ1947 Rebuilding Roads
Description The cows have reconstructed Farmer John's farm, with its N barns (1 <= N <= 150, n ...