1 条题解
-
1赵青海 (huhe) LV 7 SU @ 2022-7-13 17:27:11
/***************************************** 备注: ******************************************/ #include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N = 20; const int INF = 0x3f3f3f3f; const int Mod = 1e7 + 7; struct node { LL a[N][N]; node() { memset(a,0,sizeof(a)); for(int i = 0 ; i < N ; i++) a[i][0] = 10 ; for(int i = 1 ; i < N ; i++) for(int j = 1 ;j <= i ; j++) a[i][j] = 1; } }; int n , m; node operator * (node a , node b) { node c; memset(c.a,0 , sizeof(c.a)); for(int i = 0 ; i <= n+1 ; i++) for(int j = 0 ; j <= n+1 ; j++) { LL sum = 0; for(int k = 0 ; k <= n+1 ; k++) sum = (sum + a.a[i][k] * b.a[k][j]) %Mod; c.a[i][j] = sum; } return c; } void print(node p) { for(int i = 0 ; i <= n + 1 ; i++) { for(int j = 0 ; j <= n + 1; j ++) cout << p.a[i][j] << " "; cout << endl; } } int main() { while(cin >> n >> m) { node p; for(int i = 0 ; i <= n ; i++) p.a[n+1][i] = 0 , p.a[i][n+1] = 3; p.a[n+1][n+1] = 1; /***************************/ LL x[100]; memset(x,0,sizeof(x)); x[0] = 233; for(int i = 1; i <= n ;i++) { cin >> x[i]; x[i] = (x[i-1] + x[i])%Mod; } x[n+1] = 1LL; m--; node ans; memset(ans.a , 0 , sizeof ans.a); for(int i = 0 ; i <= n+1 ; i++) ans.a[i][i] = 1; while(m) { if(m&1) ans = ans * p; m >>= 1LL; p = p * p; } // print(ans); LL sum = 0; for(int i = 0 ; i <= n+1 ; i++ ) { sum = (sum + (x[i] * ans.a[n][i])%Mod) %Mod; } cout << sum << endl; } return 0; }
- 1
信息
- ID
- 137
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 4
- 标签
- 递交数
- 24
- 已通过
- 17
- 上传者