题意: F(1)=A,F(2)=B,F(n)=C*F(n-2)+D*F(n-1)+P/n 给定ABCDPn,求F(n) mod 1e9+7 思路: P/n在一段n里是不变的,可以数论分块,再在每一段里用矩阵快速幂 debug了一下午.. 坑点: 1.数论分块的写法要注意,已更新 2.矩阵乘法在赋值回去的时候记得模一下 3.矩阵相乘不可逆,注意看一下 代码: #include<iostream> #include<cstdio> #include<algorithm> #…
Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.Q Hand In Hand Online Acmers Forum | Discuss Statistical Charts Problem Archive Realtime Judge Status Authors Ranklist C/C++/Java Exams ACM Steps Go to Job Contest LiveC…
题目链接:传送门 题目: Recursive sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submission(s): Problem Description Farmer John likes to play mathematics games with his N cows. Recently, they are attracted…
题目链接:https://vjudge.net/problem/HDU-5950 Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2727    Accepted Submission(s): 1226 Problem Description Farmer John likes to play mat…
题目链接: Sequence Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description Holion August will eat every thing he has found. Now there are many foods,but he does not want to eat all of them at once,so he fi…
                  Yet another Number Sequence Let’s define another number sequence, given by the following function:f(0) = af(1) = bf(n) = f(n − 1) + f(n − 2), n > 1When a = 0 and b = 1, this sequence gives the Fibonacci Sequence. Changing the values…
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门  原题目描述在最下面. Solution:  一看矩阵快速幂,再一看怎么多一个变项?\(⌊ \frac{p}{n}⌋\)?  我去,\(⌊ \frac{p}{n}⌋\)这不是前几天写过的一道除法分块经典题吗?  关于除法分块,请看这里:GYM101652  然后,就没有然后了~ AC_Code: #include<bits/stdc++.h&…
Description Everyone knows what the Fibonacci sequence is. This sequence can be defined by the recurrence relation: F1 = 1, F2 = 2, Fi = Fi - 1 + Fi - 2 (i > 2). We'll define a new number sequence Ai(k) by the formula: Ai(k) = Fi × ik (i ≥ 1). In thi…
Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n).   Input The input consists of multiple test cases. Each test case…
HDU - 1005 Number Sequence Problem Description A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n). Input The input consists of multiple test…
A number sequence is defined as follows:  f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.  Given A, B, and n, you are to calculate the value of f(n). Input The input consists of multiple test cases. Each test case contains 3 integers…
[CQOI2018]交错序列 \(solution:\) 这一题出得真的很好,将原本一道矩阵快速幂硬生生加入组合数的标签,还那么没有违和感,那么让人看不出来.所以做这道题必须先知道(矩阵快速幂及如何构建递推矩阵)(组合数及二项式定理). 不知道大家有没有做过洛谷的帕秋莉手环及P哥的桶,这道题中不能有相邻的两个1就是我们在构造这个交错序列时不能连续加入两个1,这个如果直接让我们求方案数(不靠虑一的个数)就是矩阵快速幂的板子了(可以自己推递推方程).但是这1题偏偏把1的个数搭上了,我们发现1的个数是…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 Farmer John likes to play mathematics games with his N cows. Recently, they are attracted by recursive sequences. In each turn, the cows would stand in a line, while John writes two positive numbers…
接上一篇,那个递推式显然可以用矩阵快速幂优化...自己随便YY了下就出来了,学了一下怎么用LaTeX画公式,LaTeX真是个好东西!嘿嘿嘿 如上图.(刚画错了一发...已更新 然后就可以过V2了 orz CZL卡常大师,我怎么越卡越慢啊QAQ #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> #define ll long…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6395 给你一个式子,给出你A,B,C,D,P,n,让你求出第n项的式子Fn.(其中ABCDPn均在1e9的范围内) 分析: 如果Fn=C*F(n-2) + D*F(n-1) + num ; 我们就可以直接构造出这个斐波那契的矩阵快速幂 :写出相似的矩阵 1.f(n)=a*f(n-1)+b*f(n-2)+c:(a,b,c是常数) 但是这里的P/n 是变化的 , 我们无法转化出来 , 但是这里 P/n 是向…
题意:递推公式 Fn = Fn-1 + 2 * Fn-2 + n*n,让求 Fn; 析:很明显的矩阵快速幂,因为这个很像Fibonacci数列,所以我们考虑是矩阵,然后我们进行推公式,因为这样我们是无法进行运算的.好像有的思路,最后也没想出来,还是参考的大牛的博客 http://blog.csdn.net/spring371327/article/details/52973534 那是讲的很详细了,就不多说了,注意这个取模不是1e9+7,一开始忘了.. 代码如下: #pragma comment…
题意 设 $$f_i = \left\{\begin{matrix}1 , \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  i < k\\ \prod_{j=1}^k f_{i-j}^{b_j} \ mod \ p, \ \ \ \ \ i > k\end{matrix}\right.$$ 求 $f_k$($1 \leq f_k < p$),使得 $f_m = n$.($1 \leq k\leq 100$) 分析 $f_n$ 可以表示…
题目:传送门 题意: 给你m个病毒串,只由(A.G.T.C) 组成, 问你生成一个长度为 n 的 只由 A.C.T.G 构成的,不包含病毒串的序列的方案数. 解: 对 m 个病毒串,建 AC 自动机, 然后, 这个AC自动机就类似于一张有向图, 可以用邻接矩阵存这张有向图. 最多10个病毒串, 每个病毒串长度不超过 10, 那最多是个 100 * 100 的矩阵, 可以接受. 最后用矩阵快速幂加速推导. #include<cstdio> #include<cstring> #inc…
Let’s define another number sequence, given by the following function: f(0) = a f(1) = b f(n) = f(n − 1) + f(n − 2), n > 1 When a = 0 and b = 1, this sequence gives the Fibonacci Sequence. Changing the values of a and b, you can get many different se…
题目不难懂.式子是一个递推式,并且不难发现f[n]都是a的整数次幂.(f[1]=a0;f[2]=ab;f[3]=ab*f[2]c*f[1]...) 我们先只看指数部分,设h[n]. 则 h[1]=0; h[2]=b; h[3]=b+h[2]*c+h[1]; h[n]=b+h[n-1]*c+h[n-1]. h[n]式三个数之和的递推式,所以就可以转化为3x3的矩阵与3x1的矩阵相乘.于是 h[n] c  1  b h[n-1] h[n-1] = 1  0  0 * h[n-2] 1       0…
官方题解: 观察递推式我们可以发现,所有的fi​​都是a的幂次,所以我们可以对f​i​​取一个以a为底的log,g​i​​=log​a​​ f​i​​ 那么递推式变g​i​​=b+c∗g​i−1​​+g​i−2​​,这个式子可以矩阵乘法 这题有一个小trick,注意a mod p=0的情况. 分析:排除了a mod p=0的情况,幂次可以对(p-1)取模,这是由于离散对数定理 相关定理请查阅 算导 吐槽:比赛的时候就是被a mod p=0这种情况给hack掉了,我太弱了 #include <st…
Lucky Coins Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 608 Accepted Submission(s): 319 Problem Description As we all know,every coin has two sides,with one side facing up and another…
题目链接:hdu_5950_Recursive sequence 题意:递推求解:F(n) = 2*F(n-2) + F(n-1) + n4 和F(1) = a,F(2) = b: 题解: 一看数据范围,肯定矩阵加速递推,不过公式不是线性的,需要把公式转换为线性的公式 #include<bits/stdc++.h> #define F(i,a,b) for(int i=a;i<=b;i++) using namespace std; typedef long long ll; ; ll…
Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Farmer John likes to play mathematics games with his N cows. Recently, they are attracted by recursive sequences. In each turn,…
题意:已知斐波那契数列fib(i) , 给你n 和 k , 求∑fib(i)*ik (1<=i<=n) 思路:不得不说,这道题很有意思,首先我们根据以往得出的一个经验,当我们遇到 X^k 的形式,当 X 很大,k很小时,我们可以利用二项式定理进行展开,然后求出递推式在利用矩阵加速 推导过程: 已知 fib(1) = 1, fib(2) = 1,fib(i) = fib(i-1) + fib(i-2); Ai(k) =fib(i)*i^k; 根据数学归纳法,我们可知 fib(i+1)*(i+1)…
Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3832    Accepted Submission(s): 1662 Problem Description Farmer John likes to play mathematics games with his N cows. Recently…
题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1607 题目描述 A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n). 输入…
题意: \(F_n\)为斐波那契数列,\(F_1=1,F_2=2\). 给定一个\(k\),定义数列\(A_i=F_i \cdot i^k\). 求\(A_1+A_2+ \cdots + A_n\). 分析: 构造一个列向量, \({\begin{bmatrix} F_{i-1}i^0 & F_{i-1}i^1 & \cdots & F_{i-1}i^k & F_{i}i^0 & F_{i}i^1 & \cdots & F_{i}i^k &…
http://www.lightoj.com/volume_showproblem.php?problem=1065 题意:给出递推式f(0) = a, f(1) = b, f(n) = f(n - 1) +f(n - 2) 求f(n) 思路:给出了递推式就是水题. /** @Date : 2016-12-17-15.54 * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : *…
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; const int N = 4; int Mod; int msize; struct Mat { int mat[N][N]; }; Mat operator *(Mat a, Mat b) { Mat c; mems…