想问一下我的矩阵快速幂有什么问题吗???
想知道哪里导致我的快速幂变成了了龟速幂。。。。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
ll n, pr, nf, p;
ll dp[105];
int tmp[105], q[105];
typedef vector<ll> vec;
typedef vector<vec> mat;
inline mat mul(mat &x, mat &y){
mat ans(100, vec(100));
for(int i = 0; i < 100; ++i){
for(int j = 0; j < 100; ++j){
for(int k = 0; k < 100; ++k){
ans[i][j] = (ans[i][j] + x[i][k] * y[k][j] % mod) % mod;
}
}
}
return ans;
}
mat qpow(mat &x, ll y){
mat ans(100, vec(100));
for(int i = 0; i < 100; ++i)ans[i][i] = 1;
while(y){
if(y & 1)ans = mul(ans, x);
x = mul(x, x); y >>= 1;
}
return ans;
}
int main(){
cin >> n;
cin >> pr;
for(int i = 1; i <= pr; ++i)cin >> p, tmp[p] = 1;
cin >> nf;
for(int i = 1; i <= nf; ++i){
cin >> p;
if(tmp[p])q[p] = 1;
}
dp[0] = 1;
for(int i = 1; i <= 100; ++i){
for(int j = 0; j <= 100; ++j){
if(q[j] && j <= i)dp[i] = (dp[i] + dp[i - j]) % mod;
}
}
if(n <= 100)return cout << dp[n] << endl, 0;
mat orz(100, vec(100));
for(int i = 1; i <= 100; ++i)if(q[i])orz[0][i - 1] = 1;
for(int i = 1; i < 100; ++i)orz[i][i - 1] = 1;
mat matrix = qpow(orz, n - 100);
ll ans = 0;
for(int i = 0; i < 100; ++i)ans = (ans + matrix[0][i] * dp[100 - i] % mod) % mod;
cout << ans << endl; return 0;
}