7.22 H Codeforces 392C Yet Another Number Sequence
来源:互联网 发布:去眼下皱纹手术知乎 编辑:程序博客网 时间:2024/06/07 09:31
题意:
给出n和k,表示一个序列A[i],求前n项A[i]的和,结果% 1e9+7。
A[i] = i^k * F[i],F[i] = F[i-1] + F[i-2]。
思路:
矩阵快速幂。
代码:
//coder:OX_louis#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>#include <stack>using namespace std;typedef pair<int, int> pii;typedef long long ll;typedef unsigned long long ull;typedef vector<int> vi;#define MP(a,b) make_pair(a,b)#define pr(x) cout << #x << ": " << x << " "#define pl(x) cout << #x << ": " << x << endl;#define pri(a) printf("%d\n",(a))#define xx first#define yy second#define sa(n) scanf("%d", &(n))#define sal(n) scanf("%lld", &(n))#define sai(n) scanf("%I64d", &(n))#define vep(c) for(decltype((c).begin() ) it = (c).begin(); it != (c).end(); it++)#define rep(i,a,b) for(int (i)=(a); (i)<(b); (i)++)#define per(i,a,b) for(int (i)=(b)-1; (i)>=(a); (i)--)#define CLR(a,i) memset((a),(i),sizeof(a))const int mod=10000;struct Mat{ int v[2][2];}mat[50],init;Mat mt(Mat a,Mat b){ Mat ans; rep(i,0,2) rep(j,0,2){ ans.v[i][j]=0; rep(k,0,2){ ans.v[i][j]=(ans.v[i][j]+(a.v[k][j]*b.v[i][k])%mod)%mod; } } return ans;}Mat k_pow(Mat a,int n){ Mat ans=init; if(n==0)return ans; int i=1; while(n){ if(n&1){ ans=mt(ans,mat[i]); } i++; n=n>>1; } return ans;}int main(){ mat[0].v[0][0]= 1 ;mat[0].v[0][1]= 0 ; mat[0].v[1][0]= 0 ;mat[0].v[1][1]= 1 ; int T,a,b,m,n; sa(T); while(T--){ sa(a); sa(b); sa(n); sa(m); if(n==0) {pri(a);continue;} else if(n==1) {pri(b);continue;} mat[1].v[0][0]= 1 ;mat[1].v[0][1]= 1 ; mat[1].v[1][0]= 1 ;mat[1].v[1][1]= 0 ; init.v[0][0]= b ; init.v[0][1]= 0 ; init.v[1][0]= a ; init.v[1][1]= 0 ; rep(i,1,31){ mat[i+1]=mt(mat[i],mat[i]); } int mdd=1; while(m--)mdd*=10; Mat ans=k_pow(mat[1],n-1); pri(ans.v[0][0]%mdd); } return 0;}
0 0
- 7.22 H Codeforces 392C Yet Another Number Sequence
- Codeforces 392C Yet Another Number Sequence
- Codeforces 392C Yet Another Number Sequence
- [矩阵快速幂] CodeForces 392C Yet Another Number Sequence
- Codeforces 392C Yet Another Number Sequence 题解&代码
- Codeforces 392-C Yet Another Number Sequence (矩阵快速幂)
- Yet Another Number Sequence CodeForces
- Codeforces 392C Yet Another Number Sequence(矩阵快速幂)
- CodeForces 392 C.Yet Another Number Sequence(矩阵快速幂)
- CF 392C Yet Another Number Sequence(矩阵乘法)
- uva10689 Yet another Number Sequence
- UVA10689-Yet another Number Sequence
- Yet another Number Sequence UVA
- UVa 10689 - Yet another Number Sequence
- UVA 10689 Yet another Number Sequence
- UVA 10689 Yet another Number Sequence
- uva 10689 - Yet another Number Sequence(缓存,类Fibonacci)
- UVA 10689 - Yet another Number Sequence(矩阵快速幂)
- 语句或语句块中的闭包问题
- 【LightOJ 1027】A Dangerous Maze(期望)
- 分治法(Erratic Expansion,uva 12627)
- [jQuery] Cannot read property ‘msie’ of undefined错误的解决方法
- linux awk命令详解
- 7.22 H Codeforces 392C Yet Another Number Sequence
- 面试题39:平衡二叉树判断
- 服务端 缓存使用总结
- ImageView setColorFilter 滤镜效果(描边)
- sourcetree下载项目时要配置ssh公钥私钥
- 线性代数Lec01
- 如何切换svn账户
- 欢迎使用CSDN-markdown编辑器
- OpenCV ROI区域图像叠加