Codeforces 1182E Product Oriented Recurrence 矩阵快速幂
Product Oriented Recurrence
先化简原式子
c ^ x * f[x] = c ^ (x-1) * f[x-1] * c ^ (x-2) * f[x-2] * c ^ (x-3) * f[x-3]
及g[x] = c ^ x * f[x]
g[x] = g[x-1] * g[x-2] * g[x-3]
然后用矩阵快速幂计算g1, g2, g3的贡献, 计算出gn 之后 转回 fn
//#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pragma GCC optimize(4) #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x) ((int)x.size()) #define ALL(x) (x).begin(), (x).end() #define fio ios::sync_with_stdio(false); cin.tie(0);using namespace std;const int N = 1e5 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-8; const double PI = acos(-1);template<class T, class S> inline void add(T &a, S b) {a += b; if(a >= mod) a -= mod;} template<class T, class S> inline void sub(T &a, S b) {a -= b; if(a < 0) a += mod;} template<class T, class S> inline bool chkmax(T &a, S b) {return a < b ? a = b, true : false;} template<class T, class S> inline bool chkmin(T &a, S b) {return a > b ? a = b, true : false;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());LL power(LL a, LL b) {LL ans = 1;while(b) {if(b & 1) ans = ans * a % mod;a = a * a % mod; b >>= 1;}return ans; }int MOD = (int)1e9 + 6;struct Matrix {int a[3][3];Matrix() {memset(a, 0, sizeof(a));}void init() {for(int i = 0; i < 3; i++) {a[i][i] = 1;}}Matrix operator * (const Matrix &B) const {Matrix C;for(int i = 0; i < 3; i++) {for(int j = 0; j < 3; j++) {for(int k = 0; k < 3; k++) {C.a[i][j] += 1LL * a[i][k] * B.a[k][j] % MOD;if(C.a[i][j] >= MOD) C.a[i][j] -= MOD;}}}return C;}Matrix operator ^ (LL b) {Matrix C; C.init();Matrix A = (*this);while(b) {if(b & 1) C = C * A;A = A * A; b >>= 1;}return C;} } M;int mat[3][3] {{1, 1, 1},{1, 0, 0},{0, 1, 0} };LL n, f1, f2, f3, c;int main() {for(int i = 0; i < 3; i++) {for(int j = 0; j < 3; j++) {M.a[i][j] = mat[i][j];}}scanf("%lld%lld%lld%lld%lld", &n, &f1, &f2, &f3, &c);Matrix ret = M ^ (n - 3);f1 = f1 * power(c, 1) % mod;f2 = f2 * power(c, 2) % mod;f3 = f3 * power(c, 3) % mod;LL ans = 1;LL cnt1 = ret.a[0][2];LL cnt2 = ret.a[0][1];LL cnt3 = ret.a[0][0];ans = ans * power(f1, cnt1) % mod;ans = ans * power(f2, cnt2) % mod;ans = ans * power(f3, cnt3) % mod;LL inv = power(power(c, n), mod - 2);ans = ans * inv % mod;printf("%lld\n", ans);return 0; }/* */
转载于:https://www.cnblogs.com/CJLHY/p/11223481.html
Codeforces 1182E Product Oriented Recurrence 矩阵快速幂相关推荐
- codeforces 1182E Product Oriented Recurrence 矩阵快速幂
题意:设f(n) = c ^ (2n - 6) * f(n - 1) * f(n - 2) * f(n - 3), 问第n项是多少? 思路:官方题解:我们先转化一下,令g(x) = c ^ x * ...
- Product Oriented Recurrence(Codeforces Round #566 (Div. 2)E+矩阵快速幂+欧拉降幂)
传送门 题目 fn=c2∗n−6fn−1fn−2fn−3\begin{aligned} &f_n=c^{2*n-6}f_{n-1}f_{n-2}f_{n-3}&\\ \end{alig ...
- E. Product Oriented Recurrence(四个矩阵快速幂)
E. Product Oriented Recurrence time limit per test 1 second memory limit per test 256 megabytes inpu ...
- E. Product Oriented Recurrence (矩阵快速幂新模板)
E. Product Oriented Recurrence time limit per test 1 second memory limit per test 256 megabytes inpu ...
- 【Codeforces Gym - 101635C Macarons 】【矩阵快速幂+状压】【dfs时间换空间】
[链接] http://codeforces.com/gym/101635/attachments [题意] 求用1*1,1*2的方格填n*m的矩阵的方法数 [知识点] 状压dfs+矩阵快速幂 [分析 ...
- Codeforces Round #566 (Div. 2)-E. Product Oriented Recurrence
地址:https://codeforces.com/contest/1182/problem/E 思路:矩阵快速幂 fn=c^(2n−6)⋅f(n−1)⋅f(n−2)⋅f(n−3)=c^sc * f1 ...
- Codeforces 621E Wet Shark and Block【dp + 矩阵快速幂】
题意: 有b个blocks,每个blocks都有n个相同的0~9的数字,如果从第一个block选1,从第二个block选2,那么就构成12,问对于给定的n,b有多少种构成方案使最后模x的余数为k. 分 ...
- Codeforces 1106F Lunar New Year and a Recursive Sequence 矩阵快速幂,原根转化模意义下对数,BSGS
文章目录 题意 题解 对数法转指数线性递推 原根与模意义下求对数 拔山盖世! 最终步骤 Problem Origin 狠搞了一个多星期,做出来之后仍然一知半解,写个博客重理思路. 题意 定义序列fff ...
- E. Product Oriented Recurrence(codeforces R566 div2)
矩阵快速幂+欧拉降幂 思路: #include<bits/stdc++.h> using namespace std;typedef long long ll;ll mod=1e9+7;l ...
最新文章
- 【Android 应用开发】Activity 返回堆栈管理 ( 栈内复用模式 singleTask | 单实例模式 singleInstance )
- arm-linux-gcc:Command not found的问题
- Leetcode之仅仅反转字母
- excel 图片转url_最全总结 | 聊聊 Python 办公自动化之 Excel(下)
- 15. 迭代器模式(Iterator Pattern)
- 手动挖第一桶金,10日赚3十万元
- 个性化新闻文章推荐的上下文Bandit方法
- mysql 循环插入100w
- hbase 导入到es_HBase数据同步到ElasticSearch的方案
- selenium中js定位_Selenium中的定位剂
- android ios 下载地址,Ios/Android h5 唤起本地APP
- 不定积分 基本积分表
- 十大进销存管理软件亮点大对比
- 打击电商假货的社会意义
- 第九周项目5 三色球
- 1_01李婉玲_函数_1019
- 根据物理公式在Unity中实现抛物线运动.2
- 微信开通过滤 快速微信开通过滤软件
- IP定位FAQ(“准不准?”)
- 纽曼欲借“机”上位,纽扣获YunOS力挺