当前位置:网站首页>[training Day8] series [matrix multiplication]
[training Day8] series [matrix multiplication]
2022-07-24 20:10:00 【VL——MOESR】

Ideas :
We consider constructing a transition matrix
f[1] The exponent of is multiplied by b[k],f[2] The exponent of is multiplied by b[k-1]+ The original , And so on
So we can construct
0 0 0 0 …… 0 b[k]
1 0 0 0 …… 0 b[k-1]
0 1 0 0 …… 0 b[k-2]
……
0 0 0 0…… 1 b[1]
c o d e code code
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#define mo 998244352
#define ll long long
using namespace std;
ll mod = 998244353;
ll n, k;
ll f[210], c[210][210];
struct matrix
{
ll a[210][210];
matrix() {
memset(a, 0, sizeof(a)); }
}A;
matrix ans;
matrix operator *(const matrix &x,const matrix &y)
{
matrix z;
for(register int i = 0; i < k; i ++)
for(register int j = 0; j < k; j ++)
for(register int t = 0; t < k; t ++)
z.a[i][j] = (z.a[i][j] + x.a[i][t] * y.a[t][j] % mo) % mo;
return z;
}
inline matrix qpow(ll x) {
ans = A;
for(; x; A = A * A, x >>= 1)
if(x & 1) ans = ans * A;
return ans;
}
ll qpow2(ll x, ll k) {
ll ans = 1;
while(k) {
if(k & 1) ans= ans * x % mod;
x = x * x % mod;
k >>= 1;
}
return ans;
}
int main() {
freopen("seq.in", "r", stdin);
freopen("seq.out", "w", stdout);
scanf("%lld%lld", &n, &k);
for(ll i = k - 1; i >= 0; i --)
scanf("%lld", &A.a[i][k - 1]);
for(ll i = 1; i < k; i ++) A.a[i][i - 1] = 1;
for(ll i = 0; i < k; i ++) scanf("%lld", &f[i]);
if(n <= k) {
printf("%lld", f[n - 1]);
return 0;
}
n -= k;
ans = qpow(n - 1);
ll sum = 1;
for(ll i = 0; i < k; i ++)
sum = sum * qpow2(f[i], ans.a[i][k - 1]) % mod;
printf("%lld", sum);
return 0;
}
边栏推荐
- Sword finger offer 46. translate numbers into strings
- Pure C implementation -------- Nicolas theorem
- How to export map files tutorial
- 01 | 开篇词:手把手教你搭建一个博客网站
- 微服务架构 | 服务监控与隔离 - [Sentinel] TBC...
- Elastomer simulation (elasticity)
- "Six pillars of self esteem" self esteem comes from one's own feelings
- TCP sliding window, singleton mode (lazy and hungry) double checked locking / double checked locking (DCL)
- PD user manual
- clip:learning transferable visual models from natural language supervision
猜你喜欢

从码农转型大音乐家,你只差这些音乐处理工具
![Leetcode 300 longest increasing subsequence (greedy + binary search for the first element subscript smaller than nums[i]), leetcode 200 island number (deep search), leetcode 494 target sum (DFS backtr](/img/60/6b75484a65a49c6e20c2b79c062310.png)
Leetcode 300 longest increasing subsequence (greedy + binary search for the first element subscript smaller than nums[i]), leetcode 200 island number (deep search), leetcode 494 target sum (DFS backtr

Student achievement management system based on PHP

Home Assistant中接入博联WiFi智能遥控

Interface component devaxpress asp Net v22.1 - new office 365 dark theme

Install MySQL 5.7.37 on windows10

Unity2d~ game practice of decrypting Zhou mu (completed in three days)

Look at the interface control devaxpress WinForms - how to customize auxiliary function properties (Part 2)

Richview table table alignment

Elastomer simulation (elasticity)
随机推荐
Istio二之流量劫持过程
Leetcode 560 and the subarray of K (with negative numbers, one-time traversal prefix and), leetcode 438 find all alphabetic ectopic words in the string (optimized sliding window), leetcode 141 circula
How to select software dongle
2019 Hangzhou Electric Multi School Game 9 6684 Rikka with game [game question]
Valdo2021 - vascular space segmentation in vascular disease detection challenge (3)
Modbus communication protocol specification (Chinese) sharing
Click the button to return to the top smoothly
微服务架构 | 服务监控与隔离 - [Sentinel] TBC...
Valdo2021 - vascular space segmentation in vascular disease detection challenge (2)
Functional test of redisgraph multi active design scheme
Lunch break train & problem thinking: on multidimensional array statistics of the number of elements
About the largeheap attribute
Interface component devaxpress asp Net v22.1 - new office 365 dark theme
01 | 开篇词:手把手教你搭建一个博客网站
Sword finger offer 53 - I. find the number I in the sorted array
Introduction to WDK development 1- basic environment construction and the first driver (VS2010)
Analysis and Simulation of strlen function
VLAN Technology
[trial experience of Yuxin micro Wiota ad hoc network protocol development kit] RT thread BSP Software package production
TCP sliding window, singleton mode (lazy and hungry) double checked locking / double checked locking (DCL)