Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single i…
题目链接: B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculat…
题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | fn-1 | */ #include <iostream> #include <cstdio> #include <cstring> using namespace std; typedef __int64 LL; LL mod = 1e9 + ; struct data {…
CodeForces 450B Jzzhu and Sequences (矩阵优化) Description Jzzhu has invented a kind of sequences, they meet the following property: \[f_1=x\] \[f_2=y\] \[f_i=f_{i-1}+f_{i+1}\text {(i>2)}\] You are given x and y, please calculate fn modulo 1000000007 (10…
思路: 之前那篇完全没想清楚,给删了,下午一上班突然想明白了. 讲一下这道题的大概思路,应该就明白矩阵快速幂是怎么回事了. 我们首先可以推导出 学过矩阵的都应该看得懂,我们把它简写成T*A(n-1)=A(n),是不是有点像等比?然后我们得到T^(n-1)*A(1)=A(n),所以我们可以通过矩阵快速幂快速计算左边的T^n-1这个式子,最后再和A1相乘,那么第一个数字就是答案了. 代码: #include<set> #include<cstring> #include<cstd…
https://codeforces.com/contest/1117/problem/D 题意 有n个特殊宝石(n<=1e18),每个特殊宝石可以分解成m个普通宝石(m<=100),问组成n颗宝石有多少种方法 题解 数据很大:找规律or矩阵快速幂 转移方程: dp[i]=dp[i-1]+dp[i-m] 因为n<=1e18可以用矩阵快速幂 构造矩阵如图: \[ \left[ \begin{matrix} f[i-1] & f[i-2] & \cdots & f[i…
Codeforces 题面传送门 & 洛谷题面传送门 好题. 首先显然我们如果在某一次游戏中升级,那么在接下来的游戏中我们一定会一直打 \(b_jp_j\) 最大的游戏 \(j\),因为这样得到的期望收益最大. 因此我们设 \(dp_i\) 表示还剩 \(i\) 秒并且当前没有升级过的最大收益. 那么有 \(dp_i=\max\limits_{j}\{dp_{i-1}(1-p_j)+X(i-1)p_j+p_ja_j\}\),其中 \(X=\max\{b_jp_j\}\). 稍微解释一下上面的转移…
矩阵快速幂的题要多做 由题可得 g[n]=A*g[n-1]+B 所以构造矩阵  { g[n] }    =  {A   B}  * { g[n-1]} {   1   }         {0   1}     {    1    } 然后矩阵快速幂就好 矩阵快速幂的题要多做,多构造矩阵 注:其实这个题可以直接等比数列求求和,单数矩阵快速幂对于这类题更具有普遍性 #include <cstdio> #include <iostream> #include <ctime>…
矩阵快速幂. 首先得到公式 然后构造矩阵,用矩阵加速 取模函数需要自己写一下,是数论中的取模. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<algorithm> using namespace std; ; long long x, y; int n; long long mod(long long a, long long b) { )…
传送门 题意 给定序列,从序列中选择k(1≤k≤1e18)个数(可以重复选择),使得得到的排列满足\(x_i与x_{i+1}\)异或的二进制表示中1的个数是3的倍数.问长度为k的满足条件的序列有多少种? 分析 看了tags发现有关矩阵就跟最近做的矩阵快速幂联系起来了,假如ai与aj异或的数满足条件,可以看作i到j练了一条边,再异或后的数到ak也连边,那么如果找长度为3的序列,(ai,aj,ak)一定满足条件 我们可以 1.先\(O(n^2)\)预处理出k=2情况下的邻接矩阵 2.对矩阵求k-1次…