题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2604 递推式是百度的,主要是练习一下如何使用矩阵快速幂优化. 递推式:f(n)=f(n-1)+f(n-3)+f(n-4),其中f(0)=2, f(1)=4, f(2)=6, f(3)=9. 当n>4时候,需要通过这个关系来递推. 构造矩阵这种东西我以前一直认为是很玄学的,但是如果深入研究的话不难发现其实也有规律可循.这是一个齐次递推式,很好构造. 我们希望通过如下矩阵(1)得到矩阵(2) | f(n…
  (Another) YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into the enemy's base. After overcoming a series difficulties, (Another) YYF is now at the start of enemy's famous "mine road". This is a very long road…
题目大意:给你两个长度都为n,字符集为{a,b,c}的字符串S和T. 对于字符串S的任意一个字符,我们可以用cost[0]的代价,把字符a变成字符b.用cost[1]的代价,把字符b变成c,用cost[2]的代价,把字符c变成a. 问你在总代价不超过MaxCost的情况下,有多少种方法,使得字符串S与字符串T相同. 两种方法被认为是不同的,当且仅当操作序列的长度是不同的,或者某一步操作的字符不同. 数据范围:$n≤11$,$1≤cost≤10^9$,$0≤MaxCost≤10^9$. 我们先用最…
Mathematician QSC Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description QSC dream of becoming a mathematician, he believes that everything in this world has a mathematical law. Through unremitting e…
题意: 定义函数Concatenate (1 ..N)是将所有正整数 1, 2, …, N 顺序连接起来得到的数,如concatenate(1..5)是12345,求concatenate(1...n)%m的值 思路: 矩阵快速幂,公式为 $$\left[\begin{matrix}f(n)\\n\\1\end{matrix}\right]=\left[\begin{matrix}10^k&1&1\\0&1&1\\0&0&1\end{matrix}\righ…
矩阵快速幂 定义矩阵A(m*n),B(p*q),A*B有意义当且仅当n=p.即A的列数等于B的行数. 且C=A*B,C(m*q). 例如: 进入正题,由于现在全国卷高考不考矩阵,也没多大了解.因为遇到了斐波那契这题... 注意到: Fn+1=Fn+Fn-1 我们会有: 则: 所以我们只需要想办法求矩阵A的幂,这时候我们当然想要用快速幂. 代码部分: 定义矩阵: struct matrix{ ll a[][]; }; (类比整数的快速幂)预处理: [我们需要一类似于1的矩阵:] 『1 0 0 0…
https://codeforces.com/contest/1106/problem/F 题意 数列公式为\(f_i=(f^{b_1}_{i-1}*f^{b_2}_{i-2}*...*f^{b_k}_{i-k})\)mod\(P\),给出\(f_{1}...f_{k-1}\)和\(f_{n}\),求\(f_{k}\),其中\(P\)等于998244353 题解 3是998244353的离散对数,所以\(f^{b_1}_{i-1} \equiv 3^{h_i*b_1}(modP)\),怎么求离散…
Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 187893    Accepted Submission(s): 46820 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A…
Giving the N, can you tell me the answer of F(N)? Input Each test case contains a single integer N(1<=N<=10^9). The input is terminated by a set starting with N = 0. This set should not be processed. Output For each test case, output on a line the v…
题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Google Codejam Round 1A的C题. #include <bits/stdc++.h> typedef long long ll; const int N = 5; int a, b, n, mod; /* *矩阵快速幂处理线性递推关系f(n)=a1f(n-1)+a2f(n-2)+.…