codeforce#420 E. Okabe and El Psy Kongroo(图论+矩阵快速幂)
来源:互联网 发布:淘宝军刺暗语 编辑:程序博客网 时间:2024/06/05 00:07
题目链接
E. Okabe and El Psy Kongroo
分析
首先对于坐标为
AC code
#include<bits/stdc++.h>#define pb push_back#define mp make_pair#define fi first#define se second#define INF 0x3f3f3f3f#define ALL(x) (x.begin(),x.end())#define ms(x,v) memset(x,v,sizeof(x))using namespace std;typedef long long LL;typedef pair<LL,LL> Pair;typedef pair<int,pair<int,int> > Point;const int maxn = 3e5+10;const LL MOD = 1e9+7;const int sz = 16;struct matrix{ LL m[sz][sz]; matrix(){ ms(m,0); } void init(int y){ ms(m,0); for(int i=1 ; i<y ; ++i){ m[i][i+1]=m[i][i-1] = m[i][i] =1; } if(y)m[0][1]=m[0][0] = m[y][y]=m[y][y-1] =1; else m[0][0] =1; } void init(){ for(int i=0 ; i<sz ; ++i)m[i][i] =1; } void print(){ for(int i=0 ;i<sz ; ++i) { for(int j=0 ; j<sz ; ++j) std::cout << m[i][j] << ' '; std::cout << '\n'; } }};matrix mul(matrix& A,matrix & B){ matrix ret; for(int i=0 ; i<sz ; ++i){ for(int j=0 ; j<sz ; ++j){ ret.m[i][j] = 0; for(int k=0 ; k<sz ; ++k) ret.m[i][j] += A.m[i][k] * B.m[k][j],ret.m[i][j]%=MOD; } } return ret;}matrix power_mod(matrix x,LL n){ matrix ret; ret.init(); while (n) { //std::cout << "n = " <<n << '\n'; if(n&1)ret = mul(ret,x); x = mul(x,x); //ret.print(); n>>=1; } return ret;}matrix A[2];int main(){ ios::sync_with_stdio(false); cin.tie(0); LL n,k; cin>>n>>k; int t=0; ms(A,0); A[t].init(); for(LL i=0 ; i<n ;++i){ LL a,b,y; cin>>a>>b>>y; if(i == n-1)b=k; t ^=1; A[t].init(y); A[t] = power_mod(A[t],b-a); A[t] = mul(A[t^1],A[t]); } std::cout << A[t].m[0][0] << '\n'; return 0; }
参考
editorial
阅读全文
0 0
- codeforce#420 E. Okabe and El Psy Kongroo(图论+矩阵快速幂)
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo dp+矩阵快速幂
- CF round#420 div.2 E Okabe and El Psy Kongroo【矩阵快速幂】
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo(矩阵快速幂)
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo(矩阵快速幂)
- Codeforeces #420 E. Okabe and El Psy Kongroo 递推加矩阵快速幂
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo [矩阵快速幂]
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo 矩阵快速幂+dp
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo dp+矩阵快速幂
- 【codefoces821E】 Okabe and El Psy Kongroo【Dp+矩阵快速幂】
- DP 矩阵快速幂 Okabe and El Psy Kongroo:CodeForces
- Codeforces 821E Okabe and El Psy Kongroo【Dp+矩阵快速幂】套路题
- E. Okabe and El Psy Kongroo(递推+矩阵快速幂)
- Codeforces 821E Okabe and El Psy Kongroo(Dp+矩阵快速幂)
- Codeforces-821E Okabe and El Psy Kongroo(矩阵快速幂+dp)
- 【动态规划21】Codeforces Round #420 821E Okabe and El Psy Kongroo(dp+矩阵快速幂)
- E.Okabe and El Psy Kongroo
- Codeforces 821E Okabe and El Psy Kongroo 递推+矩阵幂
- Swift_Set集合(相交、集合、反相交、非包含)
- Tf.shape
- GitHub 优秀的 Android 开源项目-参考自网络
- php一些基础语法
- Android 上传资源文件中的图片
- codeforce#420 E. Okabe and El Psy Kongroo(图论+矩阵快速幂)
- Linux Audio Stack & ALSA
- linux系统编程之管道(一):匿名管道(pipe)
- Unhandled exception in ***.exe(OLE32.DLL):0xC0000005:Access Violation
- Git教程5——远程仓库
- 黄油刀butterknife在Library上的使用(元素值必须为常量表达式)
- DB2 的REORG_学习(4)_表和索引重组的分析
- 分支定界法——0-1背包问题
- openldap 镜像同步慢的问题解决