首页 技术 正文
技术 2022年11月12日
0 收藏 763 点赞 4,339 浏览 1432 个字

首先,构造出从f[][i]->f[][i+1]的转移矩阵a,和从f[i][m]->f[i+1][1]的转移矩阵b,

那么从f[1][1]转移到f[n][m]就是init*(a^(m-1)*b)^(n-1)*(a^(m-1))。

然后用用十进制快速幂(因为输入用的是10进制,这样就避免了高精度除法)。

第一次写十进制快速幂,大概的思想是维护当前位是1~9的要乘的矩阵,然后再通过这9个矩阵自己转移。

 /**************************************************************
Problem: 3240
User: idy002
Language: C++
Result: Accepted
Time:5352 ms
Memory:2764 kb
****************************************************************/ #include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#define N 1000010
#define Mod 1000000007
using namespace std; typedef long long dnt;
struct Matrix {
dnt v[][];
void make_unit() {
for( int i=; i<; i++ )
for( int j=; j<; j++ )
v[i][j] = (i==j);
}
inline const dnt* operator[]( int i ) const { return v[i]; }
Matrix(){}
Matrix( int aa, int ab, int ba, int bb ) {
v[][] = aa, v[][] = ab, v[][] = ba, v[][] = bb;
}
Matrix operator*( const Matrix &b ) const {
const Matrix &a = *this;
return Matrix( , (b[][]+a[][]*b[][])%Mod,
, a[][]*b[][]%Mod );
}
Matrix operator^( const char *b ) const {
Matrix rt, q[]; q[] = *this;
for( int i=; i<=; i++ )
q[i] = q[i-]*q[]; rt.make_unit();
for( int i=; b[i]; i++ ) {
if( b[i]-'' ) rt = rt*q[b[i]-''];
q[] = q[]*q[];
for( int j=; j<=; j++ )
q[j] = q[j-]*q[];
}
return rt;
}
}; char sn[N], sm[N];
int ln, lm;
int a, b, c, d;
Matrix ma, mb, ans; void subone( char s[] ) {
int i = ;
s[i]--;
while( s[i]<'' ) {
s[i] += ;
s[i+]--;
i++;
}
}
int main() {
scanf( "%s%s%d%d%d%d", sn, sm, &a, &b, &c, &d );
ln = strlen(sn), lm = strlen(sm);
reverse( sn, sn+ln );
reverse( sm, sm+lm );
subone(sn), subone(sm);
ma = Matrix(,b,,a)^sm;
mb = Matrix(,d,,c);
ans = ((ma*mb)^sn)*ma;
printf( "%lld\n", (ans[][]+ans[][]) % Mod );
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905