HDU 4686 Arc of Dream(递归矩阵加速)
标题效果:你就是给你一程了两个递推公式公式,第一个让你找到n结果项目。
注意需要占用该公式的复发和再构造矩阵。
Arc of Dream
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 2092 Accepted Submission(s): 664
where
a0 = A0
ai = ai-1*AX+AY
b0 = B0
bi = bi-1*BX+BY
What is the value of AoD(N) modulo 1,000,000,007?
Each test case contains 7 nonnegative integers as follows:
N
A0 AX AY
B0 BX BY
N is no more than 1018, and all the other integers are no more than 2×109.
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
///#define M 1000100
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?
0:x) #define mod 1000000007 const int maxn = 210; using namespace std; struct matrix { LL f[10][10]; }; matrix mul(matrix a, matrix b, int n) { matrix c; memset(c.f, 0, sizeof(c.f)); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { for(int k = 0; k < n; k++) c.f[i][j] += a.f[i][k]*b.f[k][j]; c.f[i][j] %= mod; } } return c; } matrix pow_mod(matrix a, LL b, int n) { matrix s; memset(s.f, 0 , sizeof(s.f)); for(int i = 0; i < n; i++) s.f[i][i] = 1LL; while(b) { if(b&1) s = mul(s, a, n); a = mul(a, a, n); b >>= 1; } return s; } matrix Add(matrix a,matrix b, int n) { matrix c; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { c.f[i][j] = a.f[i][j]+b.f[i][j]; c.f[i][j] %= mod; } } return c; } int main() { LL n; LL a, ax, ay; LL b, bx, by; while(~scanf("%I64d",&n)) { scanf("%I64d %I64d %I64d",&a, &ax, &ay); scanf("%I64d %I64d %I64d",&b, &bx, &by); a %= mod; ax %= mod; ay %= mod; b %= mod; bx %= mod; by %= mod; LL ff = a*b%mod; LL x = (a*ax+ay)%mod; LL y = (b*bx+by)%mod; LL pp = (x*y)%mod; if(n == 0) { puts("0"); continue; } matrix c; memset(c.f, 0 ,sizeof(c.f)); c.f[0][0] = ax*bx%mod; c.f[0][1] = ax*by%mod; c.f[0][2] = ay*bx%mod; c.f[0][3] = ay*by%mod; ///c.f[0][4] = 1LL; c.f[1][1] = ax; c.f[1][3] = ay; c.f[2][2] = bx; c.f[2][3] = by; c.f[3][3] = 1LL; c.f[4][0] = 1LL; c.f[4][4] = 1LL; matrix d = pow_mod(c, n-1LL, 5); LL sum = 0LL; sum += ((d.f[4][0]*pp%mod)+(d.f[4][4]*ff%mod))%mod; sum += ((d.f[4][1]*x%mod) + (d.f[4][2]*y%mod) + d.f[4][3]%mod)%mod; printf("%I64d\n",(sum+mod)%mod); } return 0; }
版权声明:本文博客原创文章,博客,未经同意,不得转载。
转载于:https://www.cnblogs.com/mfrbuaa/p/4751937.html
HDU 4686 Arc of Dream(递归矩阵加速)相关推荐
- HDU - 4686 Arc of Dream(矩阵快速幂,水题)
题目链接:点击查看 题目大意:给出定义: 现在依次给出n,A0,AX,AY,B0,BX,BY 求Aod的第n项对1e9+7取模后的结果 题目分析: 简单矩阵快速幂 首先化简一下: 初始矩阵:(取n=1 ...
- hdu 4686 Arc of Dream
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4686 题目描述: 题目上说的很清楚. 解题思路: 就是递推,用快速幂+构造矩阵解决,因为n的取值范围 ...
- HDUOJ 4686 Arc of Dream
HDUOJ 4686 Arc of Dream Problem Description An Arc of Dream is a curve defined by following function ...
- 线性代数二之矩阵加速DP——数学作业,Arc of Dream
矩阵加速 数学作业 description solution code Arc of Dream description solution code 数学作业 description solution ...
- [矩阵乘法/快速幂专题]Arc of Dream,Recursive sequence,233 Matrix,Training little cats
矩阵快速幂习题 复习矩阵乘法及快速幂模板 乘法模板 快速幂模板 T1:Arc of Dream 题目 题解 code T2:Recursive sequence 题目 题解 code T3:233 M ...
- HDU4686 Arc of Dream —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-4686 Arc of Dream Time Limit: 2000/2000 MS (Java/Others) Memo ...
- C++实现线性递归矩阵 linear recurrence matrix算法(附完整源码)
C++实现线性递归矩阵 linear recurrence matrix算法 C++实现线性递归矩阵 linear recurrence matrix算法完整源码(定义,实现,main函数测试) C+ ...
- [CQOI2018] 交错序列(矩阵加速优化dp)
problem luogu-P4456 solution 预处理阶乘和阶乘的逆元,枚举 111 出现次数 iii,∑(n−i+1i)(n−i)aib\sum\binom{n-i+1}{i}(n-i)^ ...
- 线性代数四之动态DP(广义矩阵加速)——Can you answer these queries III,保卫王国
动态DP--广义矩阵加速 SP1716 GSS3 - Can you answer these queries III description solution code [NOIP2018 提高组] ...
最新文章
- R语言dist函数距离计算实战(欧几里得距离、曼哈顿距离)
- 子弹图(Bullet chart)绘制很难吗?绘制技巧整理送你~~
- iOS之深入解析KVO的底层原理
- IDEA 错误:找不到或无法加载主类
- 【学习笔记】第四章——文件 II(基本操作、文件保护、文件系统层次结构、磁盘结构、磁盘调度算法)
- 双11个性化推荐背后,阿里云“舜天”如何应对百亿次挑战? 1
- github上的优秀项目和开发环境配置【转http://www.cnblogs.com/2018/archive/2012/11/09/2763119.html】...
- c语言中 a6,C语言中的32个关键字
- python与线性代数 矩阵
- windows 安装nginx
- java adt is保存快捷键_实用的eclipse adt 快捷键
- LGP2046[NOI2010]海拔正确性证明
- 2018数学建模论文写作方法
- 类名与样式是否为并列关系
- Word怎么在图片上制作一个简历封面?
- Matlab中矩阵的右上角有一撇表示什么意思
- TL431和PC817在开关电源中的工作详解
- 小程序接入「微信对话开放平台」,创建对话客服机器人
- PSpice 模型创建与应用实例
- Android UI系列 - 布局 - 属性详解